微信永久二维码

时间:2022-04-22 13:28:09
public function httpCurl($url,$type='get',$res='json',$arr=''){
//初始化curl
$ch=curl_init();
//设置curl的参数
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
if($type == 'post'){
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$arr);
}
//采集
$output=curl_exec($ch);
//关闭
// curl_close($ch);
if($res=='json'){
// echo curl_errno($ch);
if(curl_errno($ch)){
//请求失败 返回错误信息
return curl_errno($ch);
}else{
return json_decode($output,true);
}

}
var_dump($output);
}
//永久二维码
public function yong(){
$turl='https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=1111111111111111111&secret=22222222222222222222';
$str=file_get_contents($turl);
$new_str=json_decode($str,true);

$access_token=$new_str['access_token'];
//POST数据例子:{"action_name": "QR_LIMIT_SCENE", "action_info": {"scene": {"scene_id": 123}}}
$postArr=array(
'action_name'=>"QR_LIMIT_SCENE",
'action_info'=>array(
'scene'=>array(
'scene_id'=>2000,
),
),

);
$postJson=json_encode($postArr);
$url="https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=".$access_token;

$res=$this->httpCurl($url,'post','json',$postJson);
$ticket=$res['ticket'];
//222222222通过ticket获取二维码图片
$url='https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket='.urlencode($ticket);
// $reslist=$this->httpCurl($url);
// var_dump($reslist);
echo "<img src='$url'>";

}