$url="https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=".$access_token;
$post_data=json_encode($data);
$res=$this->request_post($post_data,$url);
//由于二进制不能转json字符串,但是可以直接写入文件变成图片,所以使用file_put_contents就能解决图片输出的问题,每一次生成二维码请求一次接口就行了。接口调用去看手册https://developers.weixin.qq.com/miniprogram/dev/api/open-api/qr-code/getWXACodeUnlimit.html
file_put_contents($_SERVER['DOCUMENT_ROOT']."/test.png",$res);
/**
* @author zhoushiwei
* @date 2018/11/2
* curl post请求
*/
public function request_post($post_data,$url) {
$postUrl = $url;
$curlPost=$post_data;
$ch = curl_init();//初始化curl
curl_setopt($ch, CURLOPT_URL,$postUrl);//抓取指定网页
curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);//跳过SSL验证
curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
$data = curl_exec($ch);//运行curl
//异常后处理
if($data===false){
$this->error("请求失败");
}
curl_close($ch);
return $data;
}
小程序二维码接口问题
最新推荐文章于 2024-05-09 16:37:16 发布