Identity card to query the free API interface code

Source: Internet
Author: User
Tags stringbuffer
Package Org.wx.xhelper.model;

/** *
 identity Card entity class
 * @author wangxw
 * @version 1.0
 * @date June, 2014 10:46:54 AM
*/public class IDCA RD {

	//ID number
	private String idcard;
	
	Date of birth
	private String born;
	
	Gender
	private String sex;
	
	The area
	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;
	}
	
	
	
}
<pre name= "code" class= "Java" >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;
	
	/** * Identity card Information Service Interface class * @author WANGXW * @version 1.0 * @date June, 2014 10:49:57 AM/public class Idcardservice { /** * Generate ID information * @param cardno * @return return ID information * @throws unsupportedencodingexception/public static String
		
		Getidcarddetail (String Cardno) throws unsupportedencodingexception{//obtain identity card information Idcard Idcard = Getidcardinfo (cardNo);
		
		Store text information StringBuffer news = new StringBuffer ();
			if (Idcard!= null) {News.append ("region:" +idcard.getatt ()). Append ("\ n");
			News.append ("Date of Birth:" +idcard.getborn ()). Append ("\ n");
		News.append ("Sex:" +idcard.getsex ()). Append ("\ n"); } if (news.length () = = 0) {news.append ("ID number"). Append (CardNO). Append ("Do not exist, please re-enter!");
	return news.tostring (); /** * Obtain ID information * @param cardno * @return return ID card information/public static Idcard Getidcardinfo (String cardno) {URL
		url = null;
		Idcard Idcard = new Idcard (); 
			try{Documentbuilderfactory factory = Documentbuilderfactory.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);
			Document 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 ();
 }
	}
	
}
http://blog.csdn.net/wangxw8746/article/details/37905213

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.