调用手机在线API获取手机号码归属地信息

时间:2022-09-10 10:45:15

手机在线(www.showji.com)始创于2001年,发展至今已拥有国内最准确、号段容量最大的手机号码归属地数据库系统,

目前号段容量将近33万条,每月保持两次以上规模数据更新,合作伙伴包括:百度、淘宝、腾讯、搜狗、小米手机、宝马汽车、

神马搜索、点心OS等。

手机在线号码归属地提供WebService、HTTP API、免费调用和付费数据库四种使用方式:

调用手机在线API获取手机号码归属地信息

可以通过URL GET超链接的方式来获取手机号归属地信息,每IP每分钟调用20次的限制,具体实现如下:

import java.util.regex.Matcher;
import java.util.regex.Pattern; /**
* 通过手机号码,获得该号码的归属地、运营商等信息
*/
public class ShoujiHelper { public static final String SHOUJI_URL = "http://v.showji.com/Locating/showji.com2016234999234.aspx";
public static final String REGEX_IS_MOBILE ="(?is)(^1[3|4|5|7|8][0-9]\\d{4,8}$)";// 正则表达式,可以只输入手机号码前7位 /**
* 根据手机号码获取归属地信息
* @param mobileNumber
* @throws Exception
*/
public static String getMobileFrom(String mobileNumber) throws Exception {
if (!veriyMobile(mobileNumber)) {
throw new Exception("不是完整的11位手机号或者正确的手机号前七位");
} String URL = SHOUJI_URL+"?m="+mobileNumber+"&output=json&callback=querycallback&timestamp="+System.currentTimeMillis();
String result = HttpUtil.readContentFromGet(URL);
if( result != null ){
result = StringUtils.substringBetween(result, "(", ")");
}
return result;
} /**
*验证手机号格式 是否符合
*@param mobileNumber
*/
public static boolean veriyMobile(String mobileNumber) {
Pattern p = Pattern.compile(REGEX_IS_MOBILE);
Matcher m = p.matcher(mobileNumber);
return m.matches();
} //测试一下
public static void main(String[] args) throws Exception { long[] phones={
18190282387L,18081685555L,18013715591L,18092163043L,18370631995L,
18026799125L,18056538590L,18038692012L,18083766020L,18092015835L,
18060923366L,18078158869L,18041153288L,18028690873L,18028796251L,
13585859733L,15961230678L,18937295656L,18056649455L,15640694239L,
18958283918L,18966551516L,15353951523L,18025114334L,15071469692L,
15139914717L,13738618263L,13181207626L,13516035175L,15327038012L,
18659138399L,15151920785L,18969515188L,13064025146L,15619969722L
}; int successNum = 0, dealNum = 20;
for(int i=0; i < dealNum; i++){
String result = getMobileFrom(phones[i]+"");
System.out.println(result);
if (result!=null && result.contains("True")) {
successNum++;
}
} System.out.println("=========================");
System.out.println("| 处理的号码总数=="+dealNum);
System.out.println("| 获取成功的个数=="+successNum);
System.out.println("| 获取失败的个数=="+(dealNum-successNum));
System.out.println("=========================");
}
}

通过GET_URL调用接口获取内容的工具类HttpUtil

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL; import org.apache.commons.io.IOUtils; public class HttpUtil { /**
* 通过GET_URL调用接口获取内容
*/
public static String readContentFromGet(String GET_URL) throws IOException {
String result = null;
BufferedReader reader = null;
HttpURLConnection connection = null; try{
String getURL = GET_URL;
URL getUrl = new URL(getURL); // 根据拼凑的URL,打开连接,URL.openConnection函数会根据URL的类型,
connection = (HttpURLConnection) getUrl.openConnection();
connection.setConnectTimeout(30000);
connection.setReadTimeout(30000);
connection.setRequestProperty("Accept-Charset", "UTF-8");
connection.setRequestProperty("contentType", "UTF-8");
connection.setRequestProperty("Content-Type", "text/xml; charset=utf-8"); // 进行连接
connection.connect();
// 取得输入流,并使用Reader读取
reader = new BufferedReader(new InputStreamReader(connection.getInputStream(),"UTF-8")); String line = null;
StringBuffer lines = new StringBuffer();
while ((line = reader.readLine()) != null) {
lines.append(line);
} result = lines.toString();
} catch (Exception e) {
System.out.println("GET_URL Result Exception : "+e.getMessage());
} finally {
// 释放资源 断开连接
IOUtils.closeQuietly(reader);
connection.disconnect();
connection = null;
}
return result;
}
}

每IP每分钟调用20次输出结果:

{"Mobile":"18190282387","QueryResult":"True","TO":"中国电信","Corp":"中国电信","Province":"四川","City":"资阳","AreaCode":"0832","PostCode":"641300","VNO":"","Card":""}
{"Mobile":"18081685555","QueryResult":"True","TO":"中国电信","Corp":"中国电信","Province":"四川","City":"资阳","AreaCode":"0832","PostCode":"641300","VNO":"","Card":""}
{"Mobile":"18013715591","QueryResult":"True","TO":"中国电信","Corp":"中国电信","Province":"江苏","City":"苏州","AreaCode":"0512","PostCode":"215000","VNO":"","Card":""}
{"Mobile":"18092163043","QueryResult":"True","TO":"中国电信","Corp":"中国电信","Province":"陕西","City":"西安","AreaCode":"029","PostCode":"710000","VNO":"","Card":""}
{"Mobile":"18370631995","QueryResult":"True","TO":"中国移动","Corp":"中国移动","Province":"江西","City":"吉安","AreaCode":"0796","PostCode":"343000","VNO":"","Card":""}
{"Mobile":"18026799125","QueryResult":"True","TO":"中国电信","Corp":"中国电信","Province":"广东","City":"江门","AreaCode":"0750","PostCode":"529000","VNO":"","Card":""}
{"Mobile":"18056538590","QueryResult":"True","TO":"中国电信","Corp":"中国电信","Province":"安徽","City":"芜湖","AreaCode":"0553","PostCode":"241000","VNO":"","Card":""}
{"Mobile":"18038692012","QueryResult":"True","TO":"中国电信","Corp":"中国电信","Province":"广东","City":"佛山","AreaCode":"0757","PostCode":"528000","VNO":"","Card":""}
{"Mobile":"18083766020","QueryResult":"True","TO":"中国电信","Corp":"中国电信","Province":"江苏","City":"扬州","AreaCode":"0514","PostCode":"225000","VNO":"","Card":""}
{"Mobile":"18092015835","QueryResult":"True","TO":"中国电信","Corp":"中国电信","Province":"陕西","City":"西安","AreaCode":"029","PostCode":"710000","VNO":"","Card":""}
{"Mobile":"18060923366","QueryResult":"True","TO":"中国电信","Corp":"中国电信","Province":"福建","City":"厦门","AreaCode":"0592","PostCode":"361000","VNO":"","Card":""}
{"Mobile":"18078158869","QueryResult":"True","TO":"中国电信","Corp":"中国电信","Province":"广西","City":"南宁","AreaCode":"0771","PostCode":"530000","VNO":"","Card":""}
{"Mobile":"18041153288","QueryResult":"True","TO":"中国电信","Corp":"中国电信","Province":"辽宁","City":"大连","AreaCode":"0411","PostCode":"116000","VNO":"","Card":""}
{"Mobile":"18028690873","QueryResult":"True","TO":"中国电信","Corp":"中国电信","Province":"广东","City":"广州","AreaCode":"020","PostCode":"510000","VNO":"","Card":""}
{"Mobile":"18028796251","QueryResult":"True","TO":"中国电信","Corp":"中国电信","Province":"广东","City":"深圳","AreaCode":"0755","PostCode":"518000","VNO":"","Card":""}
{"Mobile":"13585859733","QueryResult":"True","TO":"中国移动","Corp":"中国移动","Province":"上海","City":"上海","AreaCode":"021","PostCode":"200000","VNO":"","Card":""}
{"Mobile":"15961230678","QueryResult":"True","TO":"中国移动","Corp":"中国移动","Province":"江苏","City":"常州","AreaCode":"0519","PostCode":"213000","VNO":"","Card":""}
{"Mobile":"18937295656","QueryResult":"True","TO":"中国电信","Corp":"中国电信","Province":"河南","City":"安阳","AreaCode":"0372","PostCode":"455000","VNO":"","Card":""}
{"Mobile":"18056649455","QueryResult":"True","TO":"中国电信","Corp":"中国电信","Province":"安徽","City":"池州","AreaCode":"0566","PostCode":"247100","VNO":"","Card":""}
{"Mobile":"15640694239","QueryResult":"True","TO":"中国联通","Corp":"中国联通","Province":"辽宁","City":"锦州","AreaCode":"0416","PostCode":"121000","VNO":"","Card":""}
=========================
| 处理的号码总数==20
| 获取成功的个数==20
| 获取失败的个数==0
=========================

调用手机在线API获取手机号码归属地信息的更多相关文章

  1. HTML5调用百度地图API获取当前位置并直接导航目的地的方法

    <!DOCTYPE html> <html lang="zh-cmn-Hans">     <meta charset="UTF-8&quo ...

  2. HTML5页面直接调用百度地图API&comma;获取当前位置,直接导航目的地

    <!DOCTYPE html> <html lang="zh-cmn-Hans"> <meta charset="UTF-8"&g ...

  3. 调用webservice获取电话号码归属地信息

    首先什么是webservice ? 从广义上面讲,任何一个服务器所提供的"数据","内容","方法"等等都可以理解为webservice. ...

  4. 调用百度汇率api 获取各国的汇率值

    设置一个定时任务,每天更新汇率java代码如下 package com.thinkgem.jeesite.modules.huiLvApi.service; import java.io.Buffer ...

  5. 调用手机话费充值API的SDK编写思路

    思路 通过将SDK方法中返回的数据划分为正常返回数据以及错误返回的数据两部分,让调用者更简单的对接口调用错误进行处理. 将SDK调用第三方服务接口的流程划分为: 数据准备,http请求,结果处理三部分 ...

  6. 调用webservice查询手机号码归属地信息

    Web Services是由企业发布的完成其特定商务需求的在线应用服务,其他公司或应用软件能够通过Internet来访问并使用这项在线服务.在这里我们使用soap协议往webservice发送信息,然 ...

  7. Android手机中获取手机号码和运营商信息

    代码如下: package com.pei.activity; import android.app.Activity; import android.os.Bundle; import androi ...

  8. cordov vue项目中调用手机原生api

    cordova不仅可以把vue项目打包成app,还可以让vue借助cordova调用手机原生的api 比如拍照 比如图片上传 比如定位 比如扫描二维码 比如支付等等 Vue Cordova教程-Vue ...

  9. 淘宝&lpar;新浪&rpar;API获取IP地址位置信息

    package com.parse; import java.io.BufferedReader; import java.io.DataOutputStream; import java.io.IO ...

随机推荐

  1. iOS10字体

    iOS10字体随着手机系统的字体改变,当我们手机系统字体改变以后,我们的app的lable也会跟着一起变化: 同样的6sp,在iOS9上面运行字体显示是没问题的,当我的手机更新了iOS10以后,有的界 ...

  2. linux curl用法详解

    linux ‍‍curl用法详解 ‍‍curl的应用方式,一是可以直接通过命令行工具,另一种是利用libcurl库做上层的开发.本篇主要总结一下命令行工具的http相关的应用, 尤其是http下载方面 ...

  3. tomcat清除缓存

    方案一:点击进入解压后的tomcat,找到work文件夹,.此文件下有个catalina目录(tomcat小名叫catalina),work目录下的文件都可以删除.如果我们先前发布的一个项目有错,大家 ...

  4. JS调用ashx文件传递中文参数取不到值的解决方案

    引自:http://www.cnblogs.com/yinpeng186/archive/2011/09/30/2196726.html

  5. Java文件复制与读写

    函数介绍 public String readLine():每次读取文件的一行,当文件读取完毕时,返回null     public int read(byte[] b):将文件内容读取到字节数组b ...

  6. C入门语言基础一&lbrack;可移植性、涉及的三种文件、编程7个步骤、编译器、链接器&rsqb;

    Review Questions What dose portability mean in the context of programming? 文中讲到的可移植性是什么意思?   C本身是不涉及 ...

  7. 你不知道的JavaScript--Item13 理解 prototype&comma; getPrototypeOf 和&lowbar;&lowbar;proto&lowbar;&lowbar;

    1.深入理解prototype, getPrototypeOf和_ proto _ prototype,getPropertyOf和 _ proto _ 是三个用来访问prototype的方法.它们的 ...

  8. MATLAB用二分法、不动点迭代法及Newton迭代(切线)法求非线性方程的根

    MATLAB用二分法.不动点迭代法及Newton迭代(切线)法求非线性方程的根 作者:凯鲁嘎吉 - 博客园http://www.cnblogs.com/kailugaji/ 一.实验原理 二.实验步骤 ...

  9. &lt&semi;NET CLR via c&num; 第4版&gt&semi;笔记 第17章 委托

    17.1 初识委托 .net 通过委托来提供回调函数机制. 委托确保回调方法是类型安全的. 委托允许顺序调用多个方法. 17.2 用委托回调静态方法 将方法绑定到委托时,C# 和 CLR 都允许引用类 ...

  10. maven 生命周期、生命周期阶段、插件、目标

    生命周期maven的生命周期是抽象的,它本身不做任何实际的工作.实际的工作都由插件来完成.生命周期好比接口,插件好比实现类.maven 有三个独立的生命周期,clean.default.site. 生 ...