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