根據手機號碼查看位置和系統
業務場景描述
在一些項目中,我們會有這樣的需求,即需要開發一個API,根據用戶的手機號碼獲取對應的位置(湖南)和制式信息(聯通)。 很多人可能會問自己的左腦或者右腦,為什么中國三大運營商有這么多數字? 我們應該怎樣做呢? ? ? 你可能會突然感到不知所措、不知所措;;;我很幸運手機號怎么看歸屬地,你在中國13億多人口中遇見了我手機號怎么看歸屬地,你在數千個博客中選擇了我。 恭喜你,這一次,這一次,這一次你真的說到點子上了,因為我這個博主是上帝派來解決你的問題的; 話不多說,您想要的就在下面。 文末還有彩蛋,別忘了點開哦! ! !
注:該API由阿里巴巴提供。 無論是三大運營商的SIM卡、阿里巴巴螞蟻卡等(第三方虛擬商戶)都可以查詢! ! !
import?com.it606.utils.TelUtil;
import?org.apache.http.*;
public?class?TelUtil{
????
????public?static?String?getTelInfo(String?tel)?{
????????CloseableHttpClient?httpClient?=?HttpClients.createDefault();
????????HttpGet?get?=?new?HttpGet("http://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel="?+?tel);
????????CloseableHttpResponse?response?=?null;
????????try?{
????????????response?=?httpClient.execute(get);
????????????HttpEntity?entity?=?response.getEntity();
????????????String?telInfo?=?EntityUtils.toString(entity);
????????????String?b?=?telInfo.replace("__GetZoneResult_?=?",?"");
????????????b?=?b.replace("'",?"\"");
????????????b?=?b.replace("mts",?"\"mts\"");
????????????b?=?b.replace("province",?"\"province\"");
????????????b?=?b.replace("catName",?"\"catName\"");
????????????b?=?b.replace("telString",?"\"telString\"");
????????????b?=?b.replace("areaVid",?"\"areaVid\"");
????????????b?=?b.replace("ispVid",?"\"ispVid\"");
????????????b?=?b.replace("carrier",?"\"carrier\"");
????????????return?b;
????????}?catch?(Exception?e)?{
????????????e.printStackTrace();
????????????return?null;
????????}?finally?{
????????????try?{
????????????????if?(response?!=?null)?{
????????????????????response.close();
????????????????}
????????????}?catch?(IOException?e)?{
????????????????e.printStackTrace();
????????????}
????????????try?{
????????????????httpClient.close();
????????????}?catch?(IOException?e)?{
????????????????e.printStackTrace();
????????????}
????????}
????}
}
結果
這是文章最后的彩蛋
我聽說轉發文章
會給你帶來好運
186信息網原創文章,轉載請注明本文來自:www.2wfjd54.cn