写了个有意思的函数,通过手机号码,获取手机号码的归属省市信息
'','city'=>'');
$url = "https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query={$mobile}&resource_id=6004&ie=utf8&oe=utf8&format=json";
$result = curl_https($url);
$result = (array)json_decode($result);
if (!empty($result['data'])) {
$result = (array)$result['data'][0];
$data['city'] = empty($result['city']) ? '' : $result['city'];
$data['province'] = empty($result['prov']) ? '' : $result['prov'];
}
return $data['city'];
}
function curl_https($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);
curl_close($ch);
if(empty($result)){
return false;
}
return $result;
}
$mobile = '18014480983';
//根据手机号码获取手机号码的归属地省市信息
$localtion = getMobileLoc($mobile);
print_r($localtion);
?>
- 本文固定链接: http://www.web8899.com/2018/12/27/php通过手机号码,获取手机号码的归属省市信息/
- 转载请注明: dean 于 迈向卓越-个人博客 发表