博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
手机号码归属地查询免费api接口代码
阅读量:6972 次
发布时间:2019-06-27

本文共 3844 字,大约阅读时间需要 12 分钟。

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

手机归属地实体类

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("不存在,请又一次输入!");		}				// 截取字符串以免超出微信最大发送字符数2048		if(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

你可能感兴趣的文章
41、java与mysql乱码的问题
查看>>
细说 Form (表单)
查看>>
在Web应用和IntelliJ IDEA中使用Spring框架
查看>>
MongoDB索引相关文章-摘自网络
查看>>
2017Windows下安装pip
查看>>
用JAVA发送一个XML格式的HTTP请求
查看>>
进击的 JavaScript(一) 之 类型转换
查看>>
Android内存优化
查看>>
DECIAML字段字节计算
查看>>
电梯媒体吵架再升级,江南春张继学隔空喊话!
查看>>
angular组件版本管理器
查看>>
问题MySQL server has gone away
查看>>
iOS的Cookie存取看我绝对够!!
查看>>
Java工程师如何在1个月内做好面试准备?
查看>>
PAT A1078
查看>>
少走弯路,给Java 1~5 年程序员的建议
查看>>
纯链式golang http请求库, 支持HTTP代理
查看>>
类的扩充 js中面向对象的技术
查看>>
css 3D动画
查看>>
一名3年工作经验的java程序员应该具备的职业技能
查看>>