函数名称: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 '';
}