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

手机归属地实体类

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接口代码的更多相关文章

  1. 身份证归属地查询免费api接口代码

    描写叙述 :依据身份证编号 查询归属地信息. 身份证实体类: package org.wx.xhelper.model; /** * 身份证实体类 * @author wangxw * @versio ...

  2. 身份证归属地查询免费api接口

    描写叙述 :依据身份证编号 查询归属地信息. 调用地址: http://api.k780.com:88/? app=idcard.get&idcard=510103195309280011&a ...

  3. 违章查询免费api接口代码

    能够依据城市+车牌号+发动机号查询违章信息列表. 违章实体类 package org.wx.xhelper.model; /** * 违章实体类 * @author wangxw * @version ...

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

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

  5. 公交线路免费api接口代码

    描写叙述:本接口主要是依据城市名称 +  线路名称 模糊查找城市公交线路信息. 开源api接口:http://openapi.aibang.com/bus/lines?app_key=keyvalue ...

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

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

  7. 免费的手机号码归属地查询API接口文档

    聚合数据手机号码归属四查询API接口,根据手机号码或手机号码的前7位,查询手机号码归属地信息,包括省份 .城市.区号.邮编.运营商和卡类型. 通过链接https://www.juhe.cn/docs/ ...

  8. 百度手机号码归属地查询api与返回json处理

    前天无意间在网上看到百度ApiStore,然后好奇就进去看了看.正好最近在某博培训Android,刚学到java基础.抱着锻炼的心态选择手机号码归属地查询api进行练手.api地址 (http://a ...

  9. C# Winform实现手机号码归属地查询工具

    摘要:本文介绍使用C#开发基于Winform的手机号码归属地查询工具,并提供详细的示例代码供参考. 一.需求描述 输入正确的手机号码,查询该号码的归属地和其他相关信息. 二.需求分析 1.实现手机号码 ...

随机推荐

  1. Python 描述符(Descriptor) 附实例

    在 Python 众多原生特性中,描述符可能是最少被自定义的特性之一,但它在底层实现的方法和属性却无时不刻被使用着,它优雅的实现方式体现出 Python 简洁之美. 定义 一个描述符是一个有" ...

  2. 关于logging模块重复问题

    logger对象配置 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 import logging # 获取一个新日志logger = ...

  3. 本机机器ssh docker容器

    https://blog.csdn.net/u010324465/article/details/77184506 1.在docker中安装openssh-server 2.sudo /etc/ini ...

  4. asp.net下js调用session

    大致方法为:js调用webservise,然后通过webservise将session值返回给js完成调用 其实最主要的一点就是在webmethod中允许session:[WebMethod(Enab ...

  5. [android 代码search地址]

    http://www.androidcodesearch.com/source/packages/apps/Settings/src/com/android/settings/SecuritySett ...

  6. Consecutive Subsequence (DP+map)

    You are given an integer array of length nn. You have to choose some subsequence of this array of ma ...

  7. HDU-5319 Painter,深搜标记!

    Painter 题意:有一个棋盘n行,列数不超过50,用red和blue给这个棋盘涂色,每个格子每种颜色最多涂一次,如果两种颜色都涂了则该格子颜色为Green;red以斜杠'\'方式涂色,bule以' ...

  8. P2389 电脑班的裁员 (动态规划)

    题目背景 隔壁的新初一电脑班刚考过一场试,又到了BlingBling的裁员时间,老师把这项工作交给了ZZY来进行.而ZZY最近忙着刷题,就把这重要的任务交(tui)给了你. 题目描述 ZZY有独特的裁 ...

  9. uva 11916 解模方程a^x=b (mod n)

      Emoogle Grid  You have to color an M x N ( 1M, N108) two dimensional grid. You will be provided K  ...

  10. 【POJ3415】Common Substrings(后缀数组,单调栈)

    题意: n<=1e5 思路: 我的做法和题解有些不同 题解是维护A的单调栈算B的贡献,反过来再做一次 我是去掉起始位置不同这个限制条件先算总方案数,再把两个串内部不合法的方案数减去 式子展开之后 ...