Cell phone number attribution to query free API interface code

Source: Internet
Author: User

According to the mobile phone number to query the user's card type, operator, attribution, region and other information.

Mobile phone attribution to entity class

Package org.wx.xhelper.model;/** * Phone Attribution * @author WANGXW * @version 1.0 * @date Jul 9, 4:03:04 PM */public class Pho  Nebelong {//Phone number private string phone;//mobile number location area code private string area;//number card type private string ctype;//owned carrier private string operators;//shorthand Attribution 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;}}


Cell phone attribution to the Service interface class

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;/** * Phone attribution to service interface class * @author WANGXW * @version 1.0 * @da Te Jul 9, 4:07:11 PM */public class Phonebelongservice {/** * Generate attribution Related information * @param phone * @return Attribution information * @throws Un Supportedencodingexception */public static string Getphonebelongdetail (String phone) throws unsupportedencodingexception{//get phone attribution phonebelong Phonebelong = Getphonebelong (phone);//Store text information StringBuffer news = New StringBuffer (); if (phonebelong! = null) {News.append ("Number:" +phonebelong.getphone ()). Append ("\ n"); News.append ("Area code : "+phonebelong.getarea ()"). Append ("\ n"), News.append ("card type:" +phonebelong.getctype ()). Append ("\ n"); News.append (" Operator: "+phonebelong.getoperators ()"). Append ("\ n"), News.append ("Place of Attribution:" +phonebelong.getsimcall ()). Append ("\ n"); if (NEWs.length () = = 0) {news.append ("number"). Append (Phone). Append ("Does not exist, please reenter!");} Intercepts the string to avoid exceeding the maximum number of characters sent 2048if (News.tostring (). GetBytes ("UTF-8"). Length > 2048) {return news.substring (0, 2000/3). Concat ("..."); return news.tostring ();} /** * Get phone attribution * @param phone * @return cell phone Attribution object */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 ");D ocument 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);p Honebelong.setarea (area);p Honebelong.setctype (CType);p honebelong.setoperators ( Operators);p Honebelong.setsimcall (Simcall);}} catch (Exception e) {e.printstacktrace ();} return phonebelong;}}


Query Result:

Number: 13800138000
Area code: 010
Card type: Mobile Global Pass Card
Carrier: Mobile
Place of attribution: Beijing, China

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.