最近一个项目要整合qq互联登陆,在使用sdk的时候就发现了这个问题:
- 可能是服务器无法请求https协议
- 可能未开启curl支持,请尝试开启curl支持,重启web服务器,如果问题仍未解决,请联系我们
实在太尴尬了,网上找了些方法!感觉没有用,在通读代码以后发现了其实不是网上的方法没用而是搞错了位置,附代码:
打开php_openssl.dll模块
百度说修改api\comm\utils.php 这个实际上不是在2.1版本的SDK中这个文件已经废弃但是不知为何没有删除!实际上修改\Connect2.1\API\class\URL.class.php 地41行
/** * get_contents * 服务器通过get请求获得内容 * @param string $url 请求的url,拼接后的 * @return string 请求返回的内容 */ public function get_contents($url){ if (ini_get("allow_url_fopen") == "1") { $response = file_get_contents($url); }else{ $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_URL, $url); $response = curl_exec($ch); curl_close($ch); } //-------请求为空 if(empty($response)){ $this->error->showError("50001"); } return $response; }
替换为下面代码即可
/** * get_contents * 服务器通过get请求获得内容 * @param string $url 请求的url,拼接后的 * @return string 请求返回的内容 */ public function get_contents($url){ $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_URL, $url); $response = curl_exec($ch); curl_close($ch); //-------请求为空 if(empty($response)){ $this->error->showError("50001"); } return $response; }