|
下午在群里看到朋友要查询手机号归属地,于是就稍微看了一下。发现 手机号归属地查询 基本上都是由 手机在线 提供的 。各大网站都拿了这个公司的接口,于是我也想看看怎么获得我需要的信息,手机在线没有免费的接口,要查询手机归属地只能发送请求在他的网站页面 用正则匹配.......这方法没啥意思。
于是我继续查找,依旧是在手机在线的触屏版(m.showji.com)找到了解决方法(感谢移动互联网)。
分析:
m.showji.com 里有个api 接口直接就可以获得 json格式 手机号归属地信息, 红色的是 手机号 ...... 如下显示
http://api.showji.com/Locating/www.showji.com.aspx?m=13533333333&output=json&callback=querycallback
注:手机在线已经改了地址 具体地址需要自己到到他的网页分析。
使用的时候可以去掉后面的 &callback=querycallback 返回的就是json数据 不然还要截取处理。
发现的问题:
用 stream_context_create 创建一个header 请求结果居然要10s; 而直接file_get_contents 打开则1s不到就获得了结果。。。(不知道为什么)
代码如下:
header("content-type:text/html;charset=utf-8");
$url = "http://api.showji.com/Locating/www.showji.com.aspx";
$cellPhoneNumber = "13530552275";
$setting_array = array(
'http' => array(
'timeout' => 5,
'method' => 'GET',
'protocol_version'=>'1.1',
'header' =>
"User-Agent: Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7\r\n" .
"Host: api.showji.com\r\n" .
"Accept-Language: zh-cn,zh;q=0.8\r\n" .
"Accept: */*\r\n" .
"Referer:http://m.showji.com/\r\n" .
"Connection: keep-alive\r\n\r\n"
)
);
$headers = stream_context_create($setting_array);
//$jsons = file_get_contents($url."?m=".$cellPhoneNumber."&output=json",FALSE,$headers); //这样打开要10s
$jsons = file_get_contents($url."?m=".$cellPhoneNumber."&output=json");// 直接打开1s不到
$cellPhoneInfo = json_decode($jsons,true);
print_r($cellPhoneInfo);
//360的接口
echo file_get_contents("http://apps.qiyigoo.com/telsearch/get_tel.php?_=1370366237601&do=get_tel_info&teltype=phone&phone=13530552275&1370366237599");
当然360搜索也有一 个接口 不过返回的信息有点少,就返回城市、卡信息。
红色的是手机号 蓝色的是时间戳 请求的时候要自己替换。。
http://apps.qiyigoo.com/telsearch/get_tel.php?_=1370366237601&do=get_tel_info&teltype=phone&phone=13533333333&1370366237599 |
|
|