用CURL 访问微信接口获取token。请求没有成功 找了两天不知道什么问题
$api = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=***&secret=***";
$headerArray =array("Content-type:application/json;charset='utf-8'","Accept:application/json");
$curl = curl_init();
curl_setopt($curl,CURLOPT_USERAGENT,'PHP Curl/1.5 (+https://github.com/mod-php/curl)');
curl_setopt($curl, CURLOPT_URL,$api);
curl_setopt($curl,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl,CURLOPT_SSL_VERIFYHOST, false);
// curl_setopt($curl, CURLINFO_HEADER_OUT,true);
// curl_setopt($curl, CURLOPT_HEADER, CURLOPT_HEADER);
// curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($curl, CURLOPT_HTTPGET, true);
// curl_setopt($curl, CURLOPT_SSLVERSION, 1);
//curl_setopt($curl,CURLOPT_CAINFO,'D:\MyProject\php\xcx\cacert.pem');//这是根据http://curl.haxx.se/ca/cacert.pem 下载的证书,添加这句话之后就运行正常了
//curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器
//curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转
curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环
// curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容
/// curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回
$output = curl_exec($curl);
echo curl_error($curl);
echo json_decode($output,true);
一直出现这个 Unknown SSL protocol error in connection to api.weixin.qq.com:443 结果返回的是FALSE
curl_setopt($curl,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl,CURLOPT_SSL_VERIFYHOST, false);
网上说这样就绕过证书检测了。因为我获取token应该不需要证书吗 只有支付才要吧