其他分享
首页 > 其他分享> > 获取手机号码所在地接口

获取手机号码所在地接口

作者:互联网

function getAddress($phoneNumber){
$phoneNumber = trim($phoneNumber);
if (!preg_match('/^1[3456789]\d{9}$/', $phoneNumber)) {
return '';
}
$ch = curl_init();
$url = "https://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=".$phoneNumber."&t=".time();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// 执行HTTP请求
curl_setopt($ch, CURLOPT_URL, $url);
$res = curl_exec($ch);
$res = trim(explode('=',$res)[1]);
$res = iconv('gbk','utf-8', $res);
$infos = explode(",", $res);
$province = explode(":", $infos[1]);
return trim($province[1],"'");
}

 

$phoneaddress = getAddress('13581766382');
var_dump($phoneaddress);
exit;

标签:trim,ch,res,所在地,接口,explode,phoneNumber,手机号码,curl
来源: https://www.cnblogs.com/zdalongren/p/13362075.html