Mobile phone number attribution to query tool class

Source: Internet
Author: User
Tags soap

Import Org.w3c.dom.nodelist;import Javax.xml.parsers.documentbuilder;import Javax.xml.parsers.documentbuilderfactory;import Java.io.inputstream;import Java.io.outputstream;import Java.io.outputstreamwriter;import java.net.url;import java.net.urlconnection;/** * @Author: VIC * @Description: Cell Phone Attribution Query */public class Phoneaddressutil {private static string Getsoaprequest (String mobilecode) {Stringbuilde        R sb = new StringBuilder (); Sb.append ("<?xml version=\" 1.0\ "encoding=\" utf-8\ "?>" + "\ n" + "<soap:envelope xmlns:xsi=\" http:/                /www.w3.org/2001/xmlschema-instance\ "+" "+" xmlns:xsd=\ "http://www.w3.org/2001/xmlschema\" "+" " + "xmlns:soap=\" http://schemas.xmlsoap.org/soap/envelope/\ ">" + "\ n" + "<soap:Body>" + " \ n "+" <getmobilecodeinfo "+" "+" xmlns=\ "http://webxml.com.cn/\" > "+" \ n "+" <mo        Bilecode> "+ Mobilecode +" </mobileCode> "+" \ n "        + "<userID></userID>" + "\ n" + "</getMobileCodeInfo>" + "\ n" + "&L        T;/soap:body> "+" \ n "+" </soap:Envelope> ");    return sb.tostring (); } private static InputStream Getsoapinputstream (string mobilecode) {try {string soap = Getsoapreque            St (Mobilecode);            if (soap = = NULL) return null;            URL url = new URL ("Http://www.webxml.com.cn/WebServices/MobileCodeWS.asmx");            URLConnection conn = Url.openconnection ();            Conn.setusecaches (FALSE);            Conn.setdoinput (TRUE);            Conn.setdooutput (TRUE); Conn.setrequestproperty ("Content-type", "text/xml;            Charset=utf-8 ");            Conn.setrequestproperty ("Content-length", Integer.tostring (Soap.length ()));            Conn.setrequestproperty ("SOAPAction", "Http://WebXml.com.cn/getMobileCodeInfo");            OutputStream OS = Conn.getoutputstream (); OutpUtstreamwriter OSW = new OutputStreamWriter (OS, "UTF-8");            Osw.write (SOAP);            Osw.flush ();            Osw.close ();            Osw.close ();            InputStream is = Conn.getinputstream ();        return is;            } catch (Exception e) {e.printstacktrace ();        return null; }}//Return example Anhui anqing Anhui unicom GSM card public static string Getmobilenotrack (String mobilecode) {try {org.            W3c.dom.Document Document = null;            Documentbuilderfactory dbf = Documentbuilderfactory.newinstance ();            Dbf.setnamespaceaware (TRUE);            InputStream is = Getsoapinputstream (Mobilecode);            Documentbuilder db = Dbf.newdocumentbuilder ();            Document = Db.parse (IS);            NodeList nl = document.getElementsByTagName ("Getmobilecodeinforesult");            StringBuffer sb = new StringBuffer ();           for (int i = 0; i < nl.getlength (); i++) {Org.w3c.dom.Node n = nl.item (i);     if (N.getfirstchild (). Getnodevalue () equals ("Cell phone number Error")) {sb = new StringBuffer ("#");                Break            } sb.append (N.getfirstchild (). Getnodevalue () + "\ n");            } is.close ();        return sb.tostring ();            } catch (Exception e) {e.printstacktrace ();        return null;        }}//Get the phone belongs to the province public static string Getmobileattribution (String mobile) {string str = "";        str = phoneaddressutil.getmobilenotrack (Mobile); if (str! = NULL &&! "".            Equals (str)) {str = str.substring (Str.indexof (":") +1);            String Strarry [] = new string[]{};            Strarry = Str.split ("");            if (strarry.length >= 2) {str = strarry[0]+strarry[1];            } else {str = "no attribution information";    }} return str; }}

  

Mobile phone number attribution to query tool class

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.