/************************************************************** * Function name: http_request * Description: https请求(支持GET和POST) * Param: 参数说明 * 【in】$url string 请求url * 【in】$data array 请求发送数据 * 【in】$headers array 请求头发送数据 * 【out】$output *******************************************************************/ function http_request($url,$data = null,$headers = []){ $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); if(!empty($data)){ curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data)); } curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); if (!empty($headers)) { curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); } $output = curl_exec($curl); curl_close($curl); return $output; }