PHP curl请求https接口。直接上代码:
static public function execCurl($url){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_TIMEOUT, 60); // 60秒超时 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // https请求 不验证证书和hosts curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); $data = curl_exec($ch); $curl_errno = curl_errno($ch); $curl_error = curl_error($ch); $http_info = curl_getinfo($ch); curl_close($ch); if($curl_errno > 0 || $http_info['http_code'] != 200){ return array('result' => false, 'message' => 'HTTP CODE:' . $http_info['http_code'] . ' Error info:' . json_encode($curl_error)); } return array('result' => true, 'data' => $data); }