#### 1. 手機(jī)號(hào)歸屬地查詢(xún) --- **前期準(zhǔn)備** 沒(méi)有自己的信息庫(kù)去哪里查詢(xún)號(hào)碼信息, 當(dāng)然是找一個(gè)第三方API了 **有很多網(wǎng)站提供了在線查詢(xún)手機(jī)號(hào)歸屬地的方式** [https://www.chahaoba.com](https://www.chahaoba.com) [https://m.ip138.com](https://m.ip138.com) [https://www.ip138.com/sj](https://www.ip138.com/sj) #### 2. 使用第三方接口查詢(xún)手機(jī)號(hào)歸屬地 --- PHP 手機(jī)號(hào)歸屬地查詢(xún)接口【阿里云】 購(gòu)買(mǎi)地址: [https://market.aliyun.com/products/57126001/cmapi00035993.html#sku=yuncode2999300001](https://market.aliyun.com/products/57126001/cmapi00035993.html#sku=yuncode2999300001) **調(diào)用示例** ```php $result = mobilePlace(1503784xxxx); halt($result); ``` ```php /** * 手機(jī)號(hào)歸屬地查詢(xún) * * @param $mobile 查詢(xún)的手機(jī)號(hào) * @return array resultCode 0 查詢(xún)成功 -1 查詢(xún)失敗 */ function mobilePlace($mobile) { if (!preg_match('/^1[34578]{1}\d{9}$/', $mobile, $match)) { return ['resultCode' => -1, 'resultMsg' => '手機(jī)號(hào)格式錯(cuò)誤']; } $api = 'https://mobapi.market.alicloudapi.com/gsd'; $appcode = '85ac5eff462e433ea373b27xxxxx'; $headers = array(); array_push($headers, "Authorization:APPCODE " . $appcode); $url = $api . "?mobile=" . $mobile; $curl = curl_init(); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_FAILONERROR, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // curl_setopt($curl, CURLOPT_HEADER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); $result = curl_exec($curl); return json_decode($result, true); } ``` **查詢(xún)成功** province 歸屬地省份、city 歸屬地城市、carrier 運(yùn)營(yíng)商名稱(chēng) ```php ^ array:6 [▼ "carrier" => "移動(dòng)" "province" => "河南" "city" => "開(kāi)封" "mobile" => "1503784xxxx" "resultCode" => "0" "resultMsg" => "查詢(xún)成功!" ] ``` **查詢(xún)失敗** ```php ^ array:2 [▼ "resultCode" => -1 "resultMsg" => "手機(jī)號(hào)格式錯(cuò)誤" ] ```