手机号码归属地查询免费api接口代码
依据手机号码查询用户的卡类型、运营商、归属地、区域等信息。
手机归属地实体类
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
卡类型:移动全球通卡
运营商:移动
归属地:中国,北京
手机号码归属地查询免费api接口代码的更多相关文章
- 身份证归属地查询免费api接口代码
描写叙述 :依据身份证编号 查询归属地信息. 身份证实体类: package org.wx.xhelper.model; /** * 身份证实体类 * @author wangxw * @versio ...
- 身份证归属地查询免费api接口
描写叙述 :依据身份证编号 查询归属地信息. 调用地址: http://api.k780.com:88/? app=idcard.get&idcard=510103195309280011&a ...
- 违章查询免费api接口代码
能够依据城市+车牌号+发动机号查询违章信息列表. 违章实体类 package org.wx.xhelper.model; /** * 违章实体类 * @author wangxw * @version ...
- 快递单号查询免费api接口(PHP示例)
快递单号查询API,可以对接顺丰快递查询,邮政快递查询,中通快递查询等.这些快递物流企业,提供了快递单号自动识别接口,快递单号查询接口等快递物流服务.对于电商企业,ERP服务企业,集成此接口到自己的软 ...
- 公交线路免费api接口代码
描写叙述:本接口主要是依据城市名称 + 线路名称 模糊查找城市公交线路信息. 开源api接口:http://openapi.aibang.com/bus/lines?app_key=keyvalue ...
- 【原创】Java实现手机号码归属地查询
网络上已经有很多的手机号码归属地查询的API接口,但是这些接口总是有一些大大小小的缺陷. 总结一下这些缺陷: 1.要直接将它的搜索框链接形式粘到自己的页面,点击查询的时候还要跳转到他们的网站来展示归属 ...
- 免费的手机号码归属地查询API接口文档
聚合数据手机号码归属四查询API接口,根据手机号码或手机号码的前7位,查询手机号码归属地信息,包括省份 .城市.区号.邮编.运营商和卡类型. 通过链接https://www.juhe.cn/docs/ ...
- 百度手机号码归属地查询api与返回json处理
前天无意间在网上看到百度ApiStore,然后好奇就进去看了看.正好最近在某博培训Android,刚学到java基础.抱着锻炼的心态选择手机号码归属地查询api进行练手.api地址 (http://a ...
- C# Winform实现手机号码归属地查询工具
摘要:本文介绍使用C#开发基于Winform的手机号码归属地查询工具,并提供详细的示例代码供参考. 一.需求描述 输入正确的手机号码,查询该号码的归属地和其他相关信息. 二.需求分析 1.实现手机号码 ...
随机推荐
- Solr通过配DIH对数据库数据做索引
1 加入相关jar包 将2个相关jar包复制到/opt/solr-7.7.1/server/solr-webapp/webapp/WEB-INF/lib文件夹下 jar包名称 solr-dataimp ...
- expdp / impdp 用法详解(Oracle)
一 .关于expdp和impdp 使用EXPDP和IMPDP时应该注意的事项: EXP和IMP是客户端工具程序,它们既可以在客户端使用,也可以在服务端使用. EXPDP和IMPDP是服务端的工 ...
- spring junit4 单元测试运行正常,但是数据库并无变化
解决方案 http://blog.csdn.net/molingduzun123/article/details/49383235 原因:Spring Juint为了不污染数据,对数据的删除和更新操作 ...
- BZOJ 2720 [Violet 5]列队春游 ——期望DP
很喵的一道题(我可不是因为看了YOUSIKI的题解才变成这样的) $ans=\sum_{x<=n}\sum_{i<=n} iP(L=i)$ 其中P(x)表示视线为x的概率. 所以只需要求出 ...
- bzoj1063【Noi2008】道路设计
题意:http://www.lydsy.com/JudgeOnline/problem.php?id=1063 用一种划分方式将树划为重链和轻链,使得所有点到根节点的路径经过的轻链最大值最小 sol: ...
- 2017NOIP初赛游记
前天晚上,玩三国杀,玩到了昨天凌晨2点40多分吧,我觉得初赛要爆炸了, 不得不吐槽一下,三国杀的武将太少了. 昨天是初赛的日子,上午8点多来了后看了看阅读程序和程序填空,复习了以下理论知识和wsj 然 ...
- 稻草人(bzoj 4237)
Description JOI村有一片荒地,上面竖着N个稻草人,村民们每年多次在稻草人们的周围举行祭典. 有一次,JOI村的村长听到了稻草人们的启示,计划在荒地中开垦一片田地.和启示中的一样,田地需要 ...
- 从dataset表中获取某一列的所有值方法
原文发布时间为:2008-07-31 -- 来源于本人的百度文章 [由搬家工具导入] 可以datarow遍历所有行即可,如下:pubauthor这个表中的au_lname的所有值加到listbox上面 ...
- XPath中的轴
这个博客中有一系列的例子,不仅有child的例子:http://www.cnblogs.com/zhaozhan/archive/2009/09/10/1563723.html XPath 是一门在 ...
- Tomcat 7 的domain域名配置,Tomcat 修改JSESSIONID
https://blog.csdn.net/catoop/article/details/64581325