第一步:生成 access_token
GET https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET
第二部:生成太阳码
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;