微信生成帶引數的二維碼
阿新 • • 發佈:2019-01-11
現在微信開發平臺的開發已經越來越火,主要微信端的入口人數多,造成現在開發者很多。
今天遇到一個問題,就是微信端生成的帶引數的二維碼,來為後續推廣做準備,準備記錄一下微信公眾號方面的技術。
<?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;
}
?>