/** * curl访问接口 * @param $url :接口路径 * @param $data :所传参数 * @param $headers :设置头信息 */ function my_curl($url, $data=null, $headers=null) { $curl = curl_init(); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_URL, $url); if (!empty($headers)) { curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); } if ($data) { curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); } $res = curl_exec($curl); curl_close($curl); return $res; }