依据手机号码查询用户的卡类型、运营商、归属地、区域等信息。

手机归属地实体类

package org.wx.xhelper.model;/*** 手机归属地* @author wangxw* @version 1.0* @date Jul 9, 2014 4:03:04 PM*/
public class PhoneBelong {// 电话号码private String phone;// 手机号码所在地区区号private String area;// 号码卡类型private String ctype;// 所属运营商private String operators;// 简写归属地private String simcall;public String getPhone() {return phone;}public void setPhone(String phone) {this.phone = phone;}public String getArea() {return area;}public void setArea(String area) {this.area = area;}public String getCtype() {return ctype;}public void setCtype(String ctype) {this.ctype = ctype;}public String getOperators() {return operators;}public void setOperators(String operators) {this.operators = operators;}public String getSimcall() {return simcall;}public void setSimcall(String simcall) {this.simcall = simcall;}
}

手机归属地服务接口类

package org.wx.xhelper.service;import java.io.UnsupportedEncodingException;
import java.net.URL;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.wx.xhelper.model.PhoneBelong;/*** 手机归属地服务接口类* @author wangxw* @version 1.0* @date Jul 9, 2014 4:07:11 PM*/
public class PhoneBelongService {/*** 生成归属地相关信息* @param phone* @return 归属地相关信息* @throws UnsupportedEncodingException*/public static String getPhoneBelongDetail(String phone) throws UnsupportedEncodingException{// 获取手机归属地PhoneBelong phoneBelong = getPhoneBelong(phone);// 存储文本信息StringBuffer news = new StringBuffer();if (phoneBelong != null) {news.append("号码:"+phoneBelong.getPhone()).append("\n");news.append("区号:"+phoneBelong.getArea()).append("\n");news.append("卡类型:"+phoneBelong.getCtype()).append("\n");news.append("运营商:"+phoneBelong.getOperators()).append("\n");news.append("归属地:"+phoneBelong.getSimcall()).append("\n\n");}if(news.length() == 0){news.append("号码").append(phone).append("不存在,请又一次输入!");}// 截取字符串以免超出微信最大发送字符数2048if(news.toString().getBytes("UTF-8").length > 2048){return news.substring(0, 2000/3).concat("...");}return news.toString();}/*** 获取手机归属地* @param phone* @return 手机归属地对象*/public static PhoneBelong getPhoneBelong(String phone){URL url = null;PhoneBelong phoneBelong = new PhoneBelong();try{DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder();url = new URL("http://api.k780.com:88/?

app=phone.get&phone="+phone+"&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=xml"); Document doc = builder.parse(url.openStream()); NodeList node = doc.getElementsByTagName("result"); for(int i=0;i<node.getLength();i++){ String area = ""; String ctype = ""; String operators = ""; String simcall = ""; if(doc.getElementsByTagName("area").item(i).getFirstChild() != null){ area = doc.getElementsByTagName("area").item(i).getFirstChild().getNodeValue(); } if(doc.getElementsByTagName("ctype").item(i).getFirstChild() != null){ ctype = doc.getElementsByTagName("ctype").item(i).getFirstChild().getNodeValue(); } if(doc.getElementsByTagName("operators").item(i).getFirstChild() != null){ operators = doc.getElementsByTagName("operators").item(i).getFirstChild().getNodeValue(); } if(doc.getElementsByTagName("style_simcall").item(i).getFirstChild() != null){ simcall = doc.getElementsByTagName("style_simcall").item(i).getFirstChild().getNodeValue(); } phoneBelong.setPhone(phone); phoneBelong.setArea(area); phoneBelong.setCtype(ctype); phoneBelong.setOperators(operators); phoneBelong.setSimcall(simcall); } }catch(Exception e){ e.printStackTrace(); } return phoneBelong; } }

查询结果:

号码:13800138000
区号:010
卡类型:移动全球通卡
运营商:移动
归属地:中国,北京

转载于:https://www.cnblogs.com/gavanwanggw/p/6813139.html

手机号码归属地查询免费api接口代码相关推荐

  1. 快递单号查询免费api接口(PHP示例)

    快递单号查询API,可以对接顺丰快递查询,邮政快递查询,中通快递查询等.这些快递物流企业,提供了快递单号自动识别接口,快递单号查询接口等快递物流服务.对于电商企业,ERP服务企业,集成此接口到自己的软 ...

  2. 手机号码归属地查询[免费]

    文章目录 依赖地址 代码 依赖地址 使用百度的号码归属地查询接口 https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?resource_nam ...

  3. 三网运营商移动联通电信话费余额查询接口-携号转网识别查询/号码归属地查询-携号转网API接口

    三网话费余额查询接口,余额实时更新,非缓存,准确率极高. 携号转网的基本概念: 携号转网,也称作号码携带.移机不改号,也就是说一家电信运营商的用户,无需改变自己的手机号码,就能转而成为另一家电信运营商 ...

  4. 简易公交车查询系统c语言,公交线路免费api接口代码

    描写叙述:本接口主要是依据城市名称 +  线路名称 模糊查找城市公交线路信息. 当中cityName = URLEncoder.encode(cityName,"utf-8") l ...

  5. 银行卡归属地查询免费API

    接口地址: https://api.kertennet.com/tool/bankCardMes 返回格式: json 请求方式: GET 请求示例: https://api.kertennet.co ...

  6. 基站定位经纬度查询免费api接口-LBS数据仓库

    接口地址:http://www.cellocation.com/interfac/#cell 对你有帮助的话,右上角给个赞呗~ 

  7. java手机号归属地查询_【原创】Java实现手机号码归属地查询

    网络上已经有很多的手机号码归属地查询的API接口,但是这些接口总是有一些大大小小的缺陷. 总结一下这些缺陷: 1.要直接将它的搜索框链接形式粘到自己的页面,点击查询的时候还要跳转到他们的网站来展示归属 ...

  8. java 手机号码归属地_【原创】Java实现手机号码归属地查询

    网络上已经有很多的手机号码归属地查询的API接口,但是这些接口总是有一些大大小小的缺陷. 总结一下这些缺陷: 1.要直接将它的搜索框链接形式粘到自己的页面,点击查询的时候还要跳转到他们的网站来展示归属 ...

  9. 【原创】Java实现手机号码归属地查询

    网络上已经有很多的手机号码归属地查询的API接口,但是这些接口总是有一些大大小小的缺陷. 总结一下这些缺陷: 1.要直接将它的搜索框链接形式粘到自己的页面,点击查询的时候还要跳转到他们的网站来展示归属 ...

最新文章

  1. 半导体制冷器性能计算
  2. 随机分配座位,共50个学生,使学号相邻的同学座位不能相邻
  3. AWS昨日突发大规模故障,官方称受施工方挖断光纤影响
  4. Linux命令04:info
  5. 前端真的能做到彻底权限控制吗?
  6. 3d button - where is OS type and version detected
  7. python计算机视觉2:图像边缘检测
  8. 安卓分辨率_免费的安卓群控1数字云免费安卓群控系统
  9. 时间管理术第一原则总结
  10. raster | 栅格对象如何用于非空间模型的预测?
  11. Sublime+ZenCoding的使用
  12. centos7 zabbix
  13. 计算机软件编程英语词汇集锦
  14. 受微软信任的交叉证书将在2021年4月到期,代码签名证书将无法签内核驱动,安信教你如何才能再给驱动签名
  15. CC2530串口中断接收字符并且判断
  16. 《投射技术》与科学研究汉字笔迹心理学的希望
  17. 51单片机数码管静态显示
  18. xtu P1114 家谱
  19. vue自定义弹窗dialog,vue 点击遮罩层功能区以外的地方关闭遮罩层
  20. Intel Distiller工具包-量化实现2

热门文章

  1. 基于Java的微信公众号二次开发视频教程
  2. 国美公告暂停黄光裕及其妻杜鹃职务
  3. 数据结构:一元多项式及其基本运算
  4. 如何利用Python和win32编程避免重复性体力劳动(三)——文本框操作:WM_GETTEXT 和WM_SETTEXT
  5. 使用struts2框架来实现前台与后台的交互
  6. 基于Java+springmvc+mysql+jquery实现企业员工管理系统
  7. Linux应用(四)socket网络编程
  8. 组成原理(五)CPU指令流水线
  9. CAD表格怎么导出到Excel?CAD表格导出
  10. 计算机过去现在和未来图片,数据驱动的图形学:过去、现在和未来