php的curl获取https加密协议请求返回json数据进行信息获取

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等格式操作)
//CURLOPT_RETURNTRANSFER 将curl_exec()获取的信息以文件流的形式返回,而不是直接输出。
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;


转自:http://blog.csdn.net/qq1355541448/article/details/24790683
原文地址:https://www.cnblogs.com/luotingliang/p/7248738.html