由于短信项目的需要,需要知道目前所有手机号的归属地,于是写了一个小程序,通过在线查询,获取手机号的归属地,暂不考虑虚拟运营商和换网手机号。
代码如下:
@Test
public void tt(){
int v_i=20;
for (;v_i<99;v_i++){
get(Convert.toString(v_i));
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}finally {
}
}
}
public void get(String v_phone) {
CloseableHttpClient httpclient = HttpClients.createDefault();
String v_url="http://v.showji.com/Locating/showji.com20150108.aspx?m=1"+
v_phone+ "06331234&output=json&callback=querycallback×tamp="+
Convert.toString(System.currentTimeMillis());
try {
HttpGet httpget = new HttpGet(v_url);
CloseableHttpResponse response = httpclient.execute(httpget);
try {
HttpEntity entity = response.getEntity();
if (entity != null) {
String v_path=EntityUtils.toString(entity);
v_path=v_path.replaceAll("querycallback|;|\\)|\\(","");
if(v_path.length()<200) {
JSONObject json = JSON.parseObject(v_path);
if(!json.getString("Corp").equals("")) {
System.out.println(v_phone+" : "+json.getString("Mobile") +
" : " + json.getString("Corp"));
}
}
}
} finally {
response.close();
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
httpclient.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
运行结果如下:
30 : 13006331234 : 中国联通
31 : 13106331234 : 中国联通
32 : 13206331234 : 中国联通
33 : 13306331234 : 中国电信
34 : 13406331234 : 中国移动
35 : 13506331234 : 中国移动
36 : 13606331234 : 中国移动
37 : 13706331234 : 中国移动
38 : 13806331234 : 中国移动
39 : 13906331234 : 中国移动
45 : 14506331234 : 中国联通
47 : 14706331234 : 中国移动
49 : 14906331234 : 中国电信
50 : 15006331234 : 中国移动
51 : 15106331234 : 中国移动
52 : 15206331234 : 中国移动
53 : 15306331234 : 中国电信
55 : 15506331234 : 中国联通
56 : 15606331234 : 中国联通
57 : 15706331234 : 中国移动
58 : 15806331234 : 中国移动
59 : 15906331234 : 中国移动
70 : 17006331234 : 中国电信
76 : 17606331234 : 中国联通
77 : 17706331234 : 中国电信
78 : 17806331234 : 中国移动
80 : 18006331234 : 中国电信
81 : 18106331234 : 中国电信
82 : 18206331234 : 中国移动
83 : 18306331234 : 中国移动
84 : 18406331234 : 中国移动
85 : 18506331234 : 中国联通
86 : 18606331234 : 中国联通
87 : 18706331234 : 中国移动
88 : 18806331234 : 中国移动
89 : 18906331234 : 中国电信