curlRequest($url, $method, $headers, $bodys); Log::info("查询手机归属地{$mobile}:" . json_encode($aliData)); if (isset($aliData['code']) && $aliData['code'] == 200) { ThirdMobileLogs::query()->insert([ 'mobile' => $mobile, 'area' => $aliData['data']['area'], 'originalIsp' => $aliData['data']['originalIsp'], ]); } return $aliData['data'] ?? []; } /** * @param $url * @param $method * @param $headers * @param $bodys * @return mixed */ private function curlRequest($url, $method, $headers, $bodys){ $curl = curl_init(); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_FAILONERROR, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); //设定返回信息中是否包含响应信息头,启用时会将响应信息头作为数据流输出,true 表示输出信息头, false表示不输出信息头 //如果想将响应结果json字符串转为json数组,建议将 CURLOPT_HEADER 设置成 false curl_setopt($curl, CURLOPT_HEADER, true); if (1 == strpos("$".$url, "https://")) { curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); } curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys); curl_close($curl); list($header, $body) = explode("\r\n\r\n", curl_exec($curl), 2); Log::info("查询手机归属地1:" . $body); return json_decode($body, true); } }