php 獲取小程序碼 (B類接口)

public function qrcode(){
global $_W;
global $_GPC;

	$url_a  ="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secrt;
	$access_token = file_get_contents($url_a);
	$ac = json_decode($access_token,1);
	
	$url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=".$ac['access_token'];
			
	$data = [
        "page"=>"pages/recruit/recruit",
        "scene"=>"1",
        ];
    $post_data= json_encode($data,true);
	$qrcode = $this->api_notice_increment($url,$post_data);
	return app_json(array('url'=>$qrcode));	
}

function api_notice_increment($url,$data)
{
	$curl = curl_init();
	$a = strlen($data);
	$header = array("Content-Type: application/json; charset=utf-8","Content-Length: $a");
	curl_setopt($curl, CURLOPT_URL, $url);
	curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
	curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
	curl_setopt($curl,CURLOPT_POST,1);
	curl_setopt($curl,CURLOPT_POSTFIELDS,$data);
	curl_setopt($curl, CURLOPT_HEADER, 0);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
	$res = curl_exec($curl);
	curl_close($curl);
	return $res;

}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章