现在微信开发平台的开发已经越来越火,主要微信端的入口人数多,造成现在开发者很多。
今天遇到一个问题,就是微信端生成的带参数的二维码,来为后续推广做准备,准备记录一下微信公众号方面的技术。
<?php $access_token ="fwefweffweoifwoieo88888*****"; $url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token={$access_token}"; //临时二维码 $data = array("expire_seconds" => 604800, "action_name"=>QR_SCENE ,"action_info" =>array("scene"=>array("scene_id"=>234))); //永久二维码 // $data = array("action_name" => QR_LIMIT_STR_SCENE, "action_info" =>array("scene"=>array("scene_str"=>"234"))); $ticket_data = json_encode($data); $result = http_Post($ticket_data,$url); $jsoninfo = json_decode($result,true); $ticket = $jsoninfo["ticket"]; ?>
<?php function http_Post($data,$url) { $curl = curl_init(); curl_setopt($curl,CURLOPT_URL,$url); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); //启用时会发送一个常规的POST请求,为1或者为true if(!empty($data)){ curl_setopt($curl,CURLOPT_POST,1); curl_setopt($curl,CURLOPT_POSTFIELDS,$data);//需要要传送的内容 } curl_setopt($curl,CURLOPT_RETURNTRANSFER,1); $return_str = curl_exec($curl); curl_close($curl); return $return_str; } ?>
得到ticket后面,通过get方法直接获得对应的参数:例如直接访问:
https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=gQFC8DoAAAAAAAAAASxodHRwOi8vd2VpeGluLnFxLmNvbS9xLzZEb1k1YlhtZHhvT1lCMDlNeEtmAAIEYkCgVwMEAAAAAA==