百度手机归属地查询接口
public function tel(){
$url='http://www.baidu.com/s?wd='.$_REQUEST['tel'];
$str=$this->httpsRequestlison($url,'');
$getinfo=explode('手机号码"'.$_REQUEST['tel'],$str);
$getinfo=substr($getinfo[1],72,80);
// var_dump($getinfo);exit;
if(!$getinfo){
$getinfo='';
}elseif(strpos($getinfo,'天津')){
$getinfo='天津市';
}elseif(strpos($getinfo,'北京')){
$getinfo='北京市';
}elseif(strpos($getinfo,'重庆')){
$getinfo='重庆市';
}elseif(strpos($getinfo,'上海')){
$getinfo='上海市';
}else{
$getinfo=substr_replace($getinfo,"省",strpos($getinfo,' '),strlen(' '));//只替换第一个字符
$getinfo=substr_replace($getinfo,"市",strpos($getinfo,' '),strlen(' '));//只替换第一个字符
$getinfo=str_replace(' ', '', $getinfo);
$getinfo=str_replace("\n", '', $getinfo);
$getinfo=str_replace(" ", '', $getinfo);
$getinfo=str_replace('中国移动', '', $getinfo);
$getinfo=str_replace('中国电信', '', $getinfo);
$getinfo=str_replace('中国联通', '', $getinfo);
}
$getinfo=str_replace('</span></div>', '', $getinfo);
var_dump($getinfo);exit;
// return $getinfo;
}
function httpsRequestlison($url, $data = null){
$ch = curl_init();
//设置url
curl_setopt($ch, CURLOPT_URL, $url);
//设置curl_exec方法的返回值,结果返回,不自动输出任何内容
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if(!empty($data)){
//发送post请求,
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
}
//跳过ssl检查项
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
//发送请求
$result = curl_exec($ch);
curl_close($ch);
return $result;
}