手机号码归属地查询免费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.实现手机号码 ...
随机推荐
- i.mx53开发的一些问题
i.mx53开发的一些问题 转载于此:http://blog.csdn.net/shell_albert/article/details/8242288 原来i.mx53上4GB的Nand Fla ...
- 【实验吧】因缺思汀的绕过&&拐弯抹角&&Forms&&天网管理系统
<?php error_reporting(); if (!isset($_POST['uname']) || !isset($_POST['pwd'])) { echo '<form a ...
- 使用VS2015编写驱动时出现的部分错误以及解决方法
前几日在github上下载了一个Windows驱动的demo,原本想着直接下载下来打开解决方案就可以用,没想到一编译,出现了奇奇怪怪的Error,部分Error网上也没什么好的解决办法,对我这个从未深 ...
- Spring,Mybatis,Springmvc框架整合项目(第三部分)
一.静态资源不拦截 第二部分最后显示的几个页面其实都加载了css和js等文件,要不然不会显示的那么好看(假装好看吧),前面已经说了,我们在web.xml中配置了url的拦截形式是/,那么Dispatc ...
- spring的自动装配,骚话@Autowired的底层工作原理
前言 开心一刻 十年前,我:我交女票了,比我大两岁.妈:不行!赶紧分! 八年前,我:我交女票了,比我小两岁,外地的.妈:你就不能让我省点心? 五年前,我:我交女票了,市长的女儿.妈:别人还能看上你?分 ...
- TCP三次握手及四次挥手详解及常见面试题
https://blog.csdn.net/ZWE7616175/article/details/80432486
- Django之url上的include,URL命名和反向解析,命名空间
include其他的URLconfs #At any point, your urlpatterns can “include” other URLconf modules. This #esse ...
- android 之 ListView相关
ListView是一种列表视图,其将ListAdapter所提供的各个控件显示在一个垂直且可滚动的列表中.需要注意的为创建适配器并将其设置给ListView. 1.ArrayAdapter Array ...
- js 格式化 时间插件
// 对Date的扩展,将 Date 转化为指定格式的String // 月(M).日(d).小时(h).分(m).秒(s).季度(q) 可以用 1-2 个占位符, // 年(y)可以用 1-4 个占 ...
- Eclipse截取android报错log
Eclipse截取android报错log: 1.前提条件:已安装eclipse 2. LogCat界面设置: Logcat是Android 编程中一个命令行工具,可以用于得到程序的 log 信息,可 ...