ID attribution to query free API interface code

Source: Internet
Author: User

Descriptive narrative: According to the ID card number to query the attribution information.

Identity card entity class:

Package org.wx.xhelper.model;/** * ID entity class * @author WANGXW * @version 1.0 * @date Jul, 10:46:54 AM */public class Idcard {//ID card number private string idcard;//Birth date private string born;//sex private string sex;//region private String Att;public String Getidcard () {return idcard;} public void Setidcard (String idcard) {this.idcard = Idcard;} Public String Getborn () {return born;} public void Setborn (String born) {This.born = born;} Public String Getsex () {return sex;} public void Setsex (String sex) {this.sex = sex;} Public String Getatt () {return att;} public void Setatt (String att) {this.att = att;}}


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.idcard;/** * ID Information Service Interface class * @author WANGXW * @version 1.0 * @date Ju L-One, 10:49:57 AM */public class Idcardservice {/** * Generate ID information * @param cardno * @return return ID information * @throws unsupported Encodingexception */public static string Getidcarddetail (String Cardno) throws unsupportedencodingexception{// Get ID information Idcard Idcard = Getidcardinfo (Cardno);//Store text information StringBuffer news = new StringBuffer (); if (idcard! = null) {News.app End ("Region:" +idcard.getatt ()). Append ("\ n"); News.append ("Date of Birth:" +idcard.getborn ()). Append ("\ n"); News.append ("Gender:" +idcard.getsex ()). Append ("\ n");} if (news.length () = = 0) {news.append ("ID number"). Append (Cardno). Append ("Not present, please enter again!");} return news.tostring ();} /** * Get ID information * @param cardno * @return return ID information */public static Idcard Getidcardinfo (String cardno) {URL url = null;idcard idcard = new Idcard (); Try{documentbuilderfactory factory = Docu Mentbuilderfactory.newinstance (); Documentbuilder builder = factory.newdocumentbuilder (); url = new URL ("http://api.k780.com:88/?

App=idcard.get&idcard= "+cardno+" &appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=xml "); System.out.println (URL);D ocument doc = Builder.parse (Url.openstream ()); NodeList node = doc.getelementsbytagname ("result"); for (int i=0;i<node.getlength (); i++) {String idcard = ""; String born = ""; String sex = ""; String att = "", if (Doc.getelementsbytagname ("Idcard"). Item (i). Getfirstchild ()! = null) {Idcard = Doc.getelementsbytagname ("Idcard"). Item (i). Getfirstchild (). Getnodevalue (); if (Doc.getelementsbytagname ("Born"). Item (i). Getfirstchild ()! = null) {born = Doc.getelementsbytagname ("Born"). Item ( i). Getfirstchild (). Getnodevalue ();} if (Doc.getelementsbytagname ("Sex"). Item (i). Getfirstchild ()! = null) {sex = Doc.getelementsbytagname ("Sex"). Item (i). Getfirstchild (). Getnodevalue ();} if (Doc.getelementsbytagname ("att"). Item (i). Getfirstchild ()! = null) {att = doc.getelementsbytagname ("att"). Item (i). Getfirstchild (). Getnodevalue ();} Idcard.setidcard (Idcard); Idcard.setborn (born); Idcard.setsex (Sex); Idcard.setatt (ATT);}} catch (Exception e) {e.printstacktrace ();} return Idcard;} public static void Main (string[] args) {try {System.out.print (Getidcarddetail ("110101199001011118"));} catch ( Unsupportedencodingexception e) {e.printstacktrace ();}}}


return Result:

Area: Dongcheng District, Beijing
Born: January 01, 1990 in the day
Gender: Male

ID attribution to query free API interface code

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.