这段代码是查询指定手机号的代码归属地,输出格式为【省份+运营商】
public static String checkMobilePlace(String mobilephone)
throws IOException {
//检测手机号码归属地
URL url = new URL(
"http://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel="
+ mobilephone + "&t=" + new Date().getTime());
URLConnection urlConnection = url.openConnection();
InputStream inputStream = urlConnection.getInputStream();
//取回查询结果
String result="";
int c;
while (((c = inputStream.read()) != -1)) {
int all = inputStream.available();
byte[] b = new byte[all];
inputStream.read(b);
result += new String(b, "GBK");
}
HttpURLConnection httpConnection = (HttpURLConnection) urlConnection;
String phoneadd = result.substring(55, 57)+result.substring(76, 78);
System.out.println(phoneadd);
return phoneadd;
}
测试用例:
checkMobilePlace("15200033333");
运行结果:
河北移动