java URL 利用网址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
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; } } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?