小程序开发-curl请求curl_exec返回false,curl_error返回空

小程序开发,调用小程序登录接口获取sessionkey,使用curl_exec返回false,写法如下:

$get_token_url = 'https://api.weixin.qq.com/sns/jscode2session?appid='.$appid.'&secret='.$secret.'&js_code='.$code.'&grant_type=authorization_code';
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$get_token_url);
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
  // 需添加    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// 需添加    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$res = curl_exec($ch);curl_close($ch); echo $res;
之所以返回报错,是因为没有添加上面2句(//需添加),小程序调用的是https,必须加上面两句才可以。
--------------------- 
作者:lwyingdao 
来源:CSDN 
原文:https://blog.csdn.net/lwyingdao/article/details/80755626 
版权声明:本文为博主原创文章,转载请附上博文链接!

你可能感兴趣的:(小程序)