【微信小程序开发】后端如何返回微信小程序字体包

在微信官方文档中可以看到如果要设置小程序的字体需要满足下面的要求
微信官方文档https://developers.weixin.qq.com/miniprogram/dev/api/ui/font/wx.loadFontFace.html
【微信小程序开发】后端如何返回微信小程序字体包_第1张图片
其实后端返回的时候还需要设置响应头
php示例代码:

//返回字体
class Font
{
    public static function LogoSCUnboundedSans(){
    
	    // 获取字体文件路径
	    $fontFilePath = ROOT_PATH.'public/font/LogoSCUnboundedSans-Regular-2.ttf';
	
	    // 设置Content-Type为字体类型
	    header('Content-Type: font/ttf');
	
	    // 设置Content-Length为字体文件大小
	    header('Content-Length: ' . filesize($fontFilePath));
	
	    // 设置缓存有效期为1年
	    header('Cache-Control: public, max-age=31536000');
	    header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 31536000) . ' GMT');
	
	    // 允许跨域访问该字体资源
	    header('Access-Control-Allow-Origin: *');
	
	    // 输出字体内容
	    readfile($fontFilePath);
    }
}

【微信小程序开发】后端如何返回微信小程序字体包_第2张图片

你可能感兴趣的:(php,微信小程序,小程序)