PHP微信小程序太阳码

第一步:生成 access_token

请求地址(参考:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/access-token/auth.getAccessToken.html):

GET https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET

第二部:生成太阳码

请求地址(参考:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/qr-code/wxacode.getUnlimited.html):

POST https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=ACCESS_TOKEN

第三步:返回前端 base64 码 或 直接返回图片

1:返回base64码:

$info = base64_encode($info);

2:直接返回图片:这个需要现在本地保存,主要是把返回的数据直接file_put_contents到本地一个地方,返回路劲

// 文件目录
$dirPath = RUNTIME_PATH . 'image' . '/' . $wxapp_id;
!is_dir($dirPath) && mkdir($dirPath, 0755, true);
// 文件名称
$fileName = 'qrcode_' . md5($wxapp_id . $scene . $page) . '.png';
// 文件路径
$savePath = "{$dirPath}/{$fileName}";
if (file_exists($savePath)){
    return $savePath;
}
// 保存到文件
file_put_contents($savePath, $result);
return $savePath;

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值