php的curl獲取https加密協議請求返回json數據進行信息獲取
<?php
header("Content-type:text/html; charset=utf-8");
function getToken($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); //相當關鍵,這句話是讓curl_exec($ch)返回的結果可以進行賦值給其他的變量進行,json的數據操作,如果沒有這句話,則curl返回的數據不可以進行人為的去操作(如json_decode等格式操作)
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
return curl_exec($ch);
//$row=curl_getinfo($ch, CURLINFO_HTTP_CODE);
}
$row=getToken("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wxXXXXX&secret=1fd56a90sadfasdfxxfsdfsf");
$obj=json_decode($row);
echo $obj->access_token;<?php
header("Content-type:text/html; charset=utf-8");
function getToken($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); //相當關鍵,這句話是讓curl_exec($ch)返回的結果可以進行賦值給其他的變量進行,json的數據操作,如果沒有這句話,則curl返回的數據不可以進行人為的去操作(如json_decode等格式操作)
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
return curl_exec($ch);
//$row=curl_getinfo($ch, CURLINFO_HTTP_CODE);
}
$row=getToken("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wxXXXXX&secret=1fd56a90sadfasdfxxfsdfsf");
$obj=json_decode($row);
echo $obj->access_token;
新聞熱點
疑難解答