/**
* 创建临时二维码接口
* @return [type] [description]
*/
public static function createQrcode($status)
{
$access_token = Self::getToken();
//创建参数二维码接口
$url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token={$access_token}";
//请求数据
$postData = [
'expire_seconds'=>604800,
'action_name'=>'QR_SCENE',
'action_info'=>[
'scene'=>[
'scene_id'=>$status
],
],
];
$postData = json_encode($postData);
//$postData = '{"expire_seconds": 604800, "action_name": "QR_SCENE", "action_info": {"scene": {"scene_id": 111}}}';
//发请求
//调接口 拿到票据ticket
$data = Curl::curlPost($url,$postData);
$data = json_decode($data,true);
if(isset($data['ticket'])){ //获取成功
//通过ticket换取二维码
$url = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=".$data['ticket'];
//echo $url;die;
//保存图片到本地 // copy($url,"qrcode/1.jpg"); OR 读写文件
$img = file_get_contents($url);
$filename = "qrcode/".md5(time().rand(1000,9999)).".jpg";
file_put_contents($filename,$img);
//返回下载成功的二维码路径
return $filename;
}
return false;
}