每次创建二维码ticket需要提供一个开发者自行设定的参数(scene_id),分别介绍临时二维码和永久二维码的创建二维码ticket过程。
临时二维码请求说明
http请求URL
https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=TOKEN
POST数据格式
{ "expire_seconds": 1800,"action_name": "QR_SCENE","action_info": { "scene": { "scene_id": 100000 } } }
永久二维码请求说明
http请求URL
https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=TOKEN
POST数据格式
{ "action_name": "QR_LIMIT_SCENE",1)"> { "scene_id": 1000 } } }
完整PHP代码:别忘了替换你自己的Appid和access_token
<?PHP //创建二维码 require_once "lib.PHP"; require_once "downloadfile.PHP"; 肉盾 define("APPID","wxeebd266"); APPID define("APPSECRET","f6e52");APPSECRET $token_access_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".APPID."&secret=".APPSECRET; 获取ACCESS_TOKEN请求的URL地址; $res = file_get_contents($token_access_url); $result = json_decode($res,true);将获取的返回Json值转换为数组格式 $access_token = $result['access_token'];将获取的access_token保存到临时变量中。*/ //$access_token = "r9IM7qFARYaY7gYOPQLHujhnAkUFS4aqxhMuFao_icIHqgluuCR1Tgnq2S3BIqhlXp1pLY705xsIFhyMZeBAEqIKez9z18ivFT1aLFF40xQV6fJq6ngvwGA0C5ZEcc5UxQv_l4Szr35mrZS01yZUag"; echo $access_tokendefine("ACCESS_TOKEN",$get_msg_url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=".ACCESS_TOKEN; $rand_area = rand(1,1000$expire_seconds = ); 创建临时的ticket $post_er_array = array( "expire_seconds" => $expire_seconds,1)">临时二维码有效时间 "action_name"=>"QR_SCENE","action_info"=>( "scene"=>( "scene_id"=> $expire_seconds ) ) ); $post_json = json_encode($post_er_array); $post_json = '{"expire_seconds": 1800,"action_info": {"scene": {"scene_id": 123}}}'; //创建永久的ticket /*$post_er_array = array( "action_name"=>"QR_LIMIT_SCENE","action_info"=>array( "scene"=>array( "scene_id"=> $rand_area ) ) ); $post_json = json_encode($post_er_array); p($post_json);*/ $post_json = '{"action_name": "QR_LIMIT_SCENE","action_info": {"scene": {"scene_id": 123}}}'; $result = postMsg($get_msg_url,1)">$post_json); $arr = json_decode($result,1)">true); 获取ticket的值 //p($arr); $ticket = $arr["ticket"]; p($ticketdefine("TICKET",1)">urlencode()); 拉取二维码的URL地址 $get_erweima_url = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=".TICKET; p($get_erweima_url); 将这里的地址链接直接黏贴到浏览器地址栏访问即可查看到生成的二维码图片 echo downloadfile($get_erweima_url); 开启即可下载生成的二维码图片
上面的代码会生成一个访问二维码的地址,但是下载我找不到路径在哪里...........
downloadfile.PHP
<?function downloadfile($url,1)">$filename="",1)">$timeout=60) { $filename = empty($file) ? pathinfo($filename; $result = $url); $time = date("Y-m-d_H_i_s",1)">time()); $filename = "./catchFile/".$time.'.'.$result['extension']; $filename = "./catchFile/".$time.'.jpg'; $dir = $filename,1)">PATHINFO_DIRNAME); !is_dir($dir) && @mkdir($dir,0755,1)">true); var_dump($url); $url = str_replace(" ","%20",1)">); echo "<br />"."asdfasdf"."<br />"; if(function_exists('curl_init')) { $ch = curl_init(); curl_setopt($ch,CURLOPT_URL,1)">); $size = curl_getinfo($ch,CURLINFO_CONTENT_TYPE); //var_dump($size); curl_setopt(FALSE); 抓取https 链接的设置 curl_setopt(FALSE); curl_setopt($timeoutTRUE); $temp = curl_exec($chif(@file_put_contents($temp) && !curl_error()) { return ; } else { return false; } } { $opts = ( "http"=>( "method"=>"GET","header"=>"","timeout"=>) ); $context = stream_context_create($optscopy($file,1)">$context$http_response_header $file; } } }
原文链接:https://www.f2er.com/wxmp/881706.html