PHPcurl 请求获取access_token http_code 为0
https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_webpage_authorization.html
get请求获取access_token https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code
curl_getinfo 获取返回数据打印出来http_code = 0 是什么原因。我这边请求这个接口耗时很长。直接在服务器端运行curl 都是秒响应的。但通过php 执行就响应好长时间 还会失败,偶尔还会成功,不过耗时较长
/**
* GET 请求
* [@param](/user/param) string $url
*/
private function http_get($url) {
$oCurl = curl_init();
if (stripos($url, "https://") !== FALSE) {
curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, FALSE);
//curl_setopt($oCurl, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1
}
curl_setopt($oCurl, CURLOPT_URL, $url);
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1);
$sContent = curl_exec($oCurl);
$aStatus = curl_getinfo($oCurl);
curl_close($oCurl);
log_message('error','请求aStatus:'.json_encode($aStatus),'crul_http_get');
if (intval($aStatus["http_code"]) == 200) {
log_message('debug','curl请求成功。','crul_http_get');
return $sContent;
} else {
log_message('debug','curl请求失败。','crul_http_get');
return false;
}
}