通过手机号获取定位


function getMobileLoc($mobile){

$data = array('province'=>'','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;
}

 

$localtion = getMobileLoc($r[username]);
print_r($localtion);


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM