PHP查詢手機(jī)號碼歸屬地的方法:1、請求手機(jī)號碼歸屬查詢API;2、根據(jù)手機(jī)號碼或手機(jī)號碼的前7位,查詢手機(jī)號碼歸屬地信息;3、通過“function juheHttpRequest($url, $params = false, $ispost = 0){…}”方法請求接口返回內(nèi)容即可。
php入門到就業(yè)線上直播課:進(jìn)入學(xué)習(xí)
Apipost = Postman + Swagger + Mock + Jmeter 超好用的API調(diào)試工具:點(diǎn)擊使用
本教程操作環(huán)境:windows7系統(tǒng)、PHP8.1版、Dell G3電腦。
PHP怎么查詢手機(jī)號碼歸屬地?
基于PHP的手機(jī)號碼歸屬地查詢
手機(jī)號碼(段)歸屬地查詢
接口請求Key,可以通過https://www.juhe.cn/docs/api/id/11?s=cpphpcn
免費(fèi)申請開通
$appkey = "*********************"; //根據(jù)手機(jī)號碼或手機(jī)號碼的前7位,查詢手機(jī)號碼歸屬地信息,如省份 、城市、運(yùn)營商等。 $url = "http://apis.juhe.cn/mobile/get"; $params = [ "phone" => "1891234",//手機(jī)號碼或手機(jī)號碼的前7位 "key" => $appkey,//應(yīng)用APPKEY(應(yīng)用詳細(xì)頁查詢) ]; $paramstring = http_build_query($params); $content = juheHttpRequest($url, $paramstring, 1); $result = json_decode($content, true); if ($result) { if ($result['error_code'] == 0) { echo "省份:{$result['result']['province']}" . PHP_EOL; echo "城市:{$result['result']['city']}" . PHP_EOL; echo "區(qū)號:{$result['result']['areacode']}" . PHP_EOL; echo "運(yùn)營商:{$result['result']['company']}" . PHP_EOL; } else { echo "{$result['error_code']}:{$result['reason']}" . PHP_EOL; } } else { echo "請求失敗"; } /** * 請求接口返回內(nèi)容 * @param string $url [請求的URL地址] * @param string $params [請求的參數(shù)] * @param int $ipost [是否采用POST形式] * @return string */ function juheHttpRequest($url, $params = false, $ispost = 0) { $httpInfo = array(); $ch = curl_init(); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($ch, CURLOPT_USERAGENT, 'JuheData'); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3); curl_setopt($ch, CURLOPT_TIMEOUT, 5); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); if ($ispost) { curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $params); curl_setopt($ch, CURLOPT_URL, $url); } else { if ($params) { curl_setopt($ch, CURLOPT_URL, $url . '?' . $params); } else { curl_setopt($ch, CURLOPT_URL, $url); } } $response = curl_exec($ch); if ($response === FALSE) { //echo "cURL Error: " . curl_error($ch); return false; } $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $httpInfo = array_merge($httpInfo, curl_getinfo($ch)); curl_close($ch); return $response; }
登錄后復(fù)制
推薦學(xué)習(xí):《PHP視頻教程》