php通過手機號查詢歸屬地,使用免費介面,資料量6W+以上
函式名稱:get_mobile_area
引數列表:$mobile表示需要查詢的手機號
具體實現:
function get_mobile_area($mobile){
if (empty($mobile)) {
return '';
}
$url = "http://mobsec-dianhua.baidu.com/dianhua_api/open/location?tel=".$mobile;
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch , CURLOPT_URL , $url);
$res = curl_exec($ch);
$data_arr = json_decode($res,true);
if ($data_arr['responseHeader']['status'] == 200) {
return $data_arr['response'][$mobile]['location'];
}
return '';
}