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

手机归属地实体类

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. Lex与Yacc学习(六)之lex & yacc (简单计算器程序) 运行

    词法分析程序ch3-01.l %{ #include "ch3-01.tab.h" extern int yylval; %} %% [0-9]+ { yylval = atoi( ...

  2. 排序算法C语言实现——快速排序的递归和非递归实现

    /*快排 -  递归实现nlogn*//*原理:    快速排序(Quicksort)是对冒泡排序的一种改进.    快速排序由C. A. R. Hoare在1962年提出.它的基本思想是:通过一趟排 ...

  3. Makefile学习(二)----生成静态库文件

    Lunix下编译静态库文件: .o后缀文件:编译生成的中间代码文件: .a后缀文件:静态库文件,编译的时候会合到可执行程序中,文件比较大: .so后缀文件:动态库文件,只是一个指向,不会合到可执行程序 ...

  4. windons杀死8080进程

    1,netstat -aon|findstr "8080" //8080端口号 2,taskkill -PID 2976 -F //2976 ,8080端口号对应的进程号

  5. SQLAlchemy常用操作

    Models 只是配置和使用比较简单,因为他是Django自带的ORM框架,也正是因为是Django原生的,所以兼容性远远不如SQLAlchemy 真正算得上全面的ORM框架必然是我们的SQLAlch ...

  6. 4A. Just a Hook

    4A. Just a Hook Time Limit: 2000ms Case Time Limit: 2000ms Memory Limit: 32768KB   64-bit integer IO ...

  7. JSON.parse与eval区别

    两种方式都可以解析json字符串,不过有时候JSON.parse解析会失败,失败原因有多种,下面会指出一种. JSON.parse()解析json格式的数据,会对要解析的字符串进行格式检查,如果格式不 ...

  8. nginx的详解(四)

    10.nginx的访问控制及DDOS预防1)访问控制配置基于各种原因,Ningx有时要进行访问控制.比如说,一般网站的后台都不能让外部访问,所以要添加 IP 限制,通常只允许公司的IP访问.访问控制就 ...

  9. [UOJ#223][BZOJ4654][Noi2016]国王饮水记

    [UOJ#223][BZOJ4654][Noi2016]国王饮水记 试题描述 跳蚤国有 n 个城市,伟大的跳蚤国王居住在跳蚤国首都中,即 1 号城市中.跳蚤国最大的问题就是饮水问题,由于首都中居住的跳 ...

  10. Codeforces633G - Yash And Trees

    Portal Description 给出一个\(n(n\leq10^5)\)个点的带点权树,以\(1\)为根:以及正整数\(m(m\leq10^3)\).进行\(q(q\leq10^5)\)次操作: ...