手机号码归属地查询api接口
Posted 壹度技术
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了手机号码归属地查询api接口相关的知识,希望对你有一定的参考价值。
1、淘宝网
API地址: http://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=手机号码
参数:
tel:手机号码
返回:JSON
2、拍拍
API地址: http://virtual.paipai.com/extinfo/GetMobileProductInfo?mobile=手机号码&amount=10000&callname=getPhoneNumInfoExtCallback
参数:
mobile:手机号码
callname:回调函数
amount:未知(必须)
返回:JSON
3、财付通
API地址: http://life.tenpay.com/cgi-bin/mobile/MobileQueryAttribution.cgi?chgmobile=手机号码
参数:
chgmobile:手机号码
返回:xml
4、百付宝
API地址: https://www.baifubao.com/callback?cmd=1059&callback=phone&phone=手机号码
参数:
phone:手机号码
callback:回调函数
cmd:未知(必须)
返回:JSON
5、115
API地址: http://cz.115.com/?ct=index&ac=get_mobile_local&callback=jsonp1333962541001&mobile=手机号码
参数:
mobile:手机号码
callback:回调函数
返回:JSON
php代码实现(通过正则解析返回数据)
$url="https://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=".$input; $info=file_get_contents($url); preg_match_all("/(w+):‘([^‘]+)/", $info, $m); $a = array_combine($m[1], $m[2]); var_dump($a) ;
java代码实现
利用淘宝的查询接口api 网址URL:https://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=188xxxxxxxx
淘宝的查询接口 返回的JSON格式:
__GetZoneResult_ = { mts:‘188xxxx‘, province:‘浙江‘, catName:‘中国移动‘, telString:‘188xxxxxxxx‘, areaVid:‘30510‘, ispVid:‘3236139‘, carrier:‘浙江移动‘ }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
public static String calcMobileCity(String mobileNumber) throws MalformedURLException { //获取拍拍网的API地址 // String urlString = "http://virtual.paipai.com/extinfo/GetMobileProductInfo?mobile=" // + mobileNumber + "&amount=10000&callname=getPhoneNumInfoExtCallback"; //淘宝网的API地址 String urlString = "https://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=" + mobileNumber; StringBuffer sb = new StringBuffer(); BufferedReader buffer; URL url = new URL(urlString); String province = "" ; try { //获取URL地址中的页面内容 InputStream in = url.openStream(); // 解决乱码问题 buffer = new BufferedReader( new InputStreamReader(in, "gb2312" )); String line = null ; //一行一行的读取数据 while ((line = buffer.readLine()) != null ) { sb.append(line); } in.close(); buffer.close(); System.out.println(sb.toString()); //定义两种不同格式的字符串 // __GetZoneResult_ = { mts:‘1594578‘, province:‘黑龙江‘, catName:‘中国移动‘, telString:‘15945782060‘, areaVid:‘30496‘, ispVid:‘3236139‘, carrier:‘黑龙江移动‘} String objectStr = "{"mts":"1594578","province":"黑龙江","catName":"中国移动","telString":"15945782060","areaVid":"30496","ispVid":"3236139","carrier":"黑龙江移动"}" ; //1、使用JSONObject JSONObject jsonObject2 = JSONObject.fromObject(objectStr); String pro1 = jsonObject2.getString( "province" ); System.out.println(pro1); MobileTest stu = (MobileTest) JSONObject.toBean(jsonObject2, MobileTest. class ); province = stu.getProvince(); System.out.println(province); } catch (Exception e) { e.printStackTrace(); } //从JSONObject对象中读取城市名称 return province /*jsonObject.getString("cityname")*/ ; } |
json对象对应的实体类:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
public class MobileTest { private int mts; private String province; private String catName; private String telString; private int areaVid; private int ispVid; private String carrier; public int getMts() { return mts; } public void setMts( int mts) { this .mts = mts; } public String getProvince() { return province; } public void setProvince(String province) { this .province = province; } public String getCatName() { return catName; } public void setCatName(String catName) { this .catName = catName; } public String getTelString() { return telString; } public void setTelString(String telString) { this .telString = telString; } public int getAreaVid() { return areaVid; } public void setAreaVid( int areaVid) { this .areaVid = areaVid; } public int getIspVid() { return ispVid; } public void setIspVid( int ispVid) { this .ispVid = ispVid; } public String getCarrier() { return carrier; } public void setCarrier(String carrier) { this .carrier = carrier; } } |
以上是关于手机号码归属地查询api接口的主要内容,如果未能解决你的问题,请参考以下文章