本文是在java平台上编写的二代身份证信息查询程序,可以查询二代身份证的基本信息,包括文字信息和图像信息。用到的Jar包是JNative.jar,这个很容易就能下载到,下载后添加到工程的外部jar库中。另外,程序装载了sdtapi.DLL和WltRS.DLL文件,这两个文件必须放到C:\\Windows\\System32目录下。只有一个java文件,需要说明的是:用到的测试设备接口是RS232串口,USB的接口程序可自行修改。资料是在网上用积分买的,现免费共享给手上没有积分的朋友下载。
package com.a;
import javax.swing.*; import org.xvolks.jnative.JNative; import org.xvolks.jnative.Type; import org.xvolks.jnative.exceptions.NativeException; import org.xvolks.jnative.pointers.Pointer; import org.xvolks.jnative.pointers.memory.MemoryBlockFactory; import java.awt.*; import javax.imageio.ImageIO; import java.io.*; import java.util.StringTokenizer; import java.awt.event.*;
public cla IdentityInfoReader extends JFrame implements ActionListener { private static final long serialVersionUID = -8959055752439578441L; JLabel[] label = new JLabel[10]; JButton showBmp; JTextField[] text = new JTextField[9]; String[] labelItem = {\"姓名:\", \"性别:\", \"民族:\", \"出生年月:\", \"地址:\", \"身份证号:\", \"签发机构:\", \"期限起始:\", \"期限终止:\"}; JNative openJN = null, findJN = null, selectJN = null, readJN = null, MngJN = null, BmpJN = null, closeJN = null; JButton readJB, exitJB; int iPort = 1; int iIfOpen = 1;
public InformationReader(String str) {
super(str);
System.loadLibrary(\"sdtapi\");
try {
try {
init();
} catch (NativeException e) {
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
} catch (IllegalAcceException e) {
}
label[0] = new JLabel(\"二代身份证信息\");
label[0].setBounds(200, 20, 95, 25);
getContentPane().add(label[0]);
for (int j = 1; j
label[j] = new JLabel(labelItem[j1]); } text[0].setText(Info[0]); if (Info[1].charAt(0) == \'1\') { text[1].setText(\"男\"); } else if (Info[1].charAt(0) == \'2\') text[1].setText(\"女\"); char[] nationChar = new char[2]; Info[1].getChars(1, 3, nationChar, 0); String nationStr = \"\"; nationStr = String.valueOf(nationChar); if (nationStr.equals(\"01\")) text[2].setText(\"汉\"); else if (nationStr.equals(\"02\")) text[2].setText(\"蒙古族\"); else if (nationStr.equals(\"03\")) text[2].setText(\"回族\"); else if (nationStr.equals(\"04\")) text[2].setText(\"藏族\"); else if (nationStr.equals(\"05\")) text[2].setText(\"维吾尔族\"); else if (nationStr.equals(\"06\")) text[2].setText(\"苗族\"); else if (nationStr.equals(\"07\")) text[2].setText(\"彝族\"); else if (nationStr.equals(\"08\")) text[2].setText(\"壮族\"); else if (nationStr.equals(\"09\")) text[2].setText(\"布依族\"); else if (nationStr.equals(\"10\")) text[2].setText(\"朝鲜族\"); else if (nationStr.equals(\"11\")) text[2].setText(\"满族\"); else if (nationStr.equals(\"12\")) text[2].setText(\"侗族\"); else if (nationStr.equals(\"13\")) text[2].setText(\"瑶族\"); else if (nationStr.equals(\"14\")) text[2].setText(\"白族\"); else if (nationStr.equals(\"15\")) text[2].setText(\"土家族\"); else if (nationStr.equals(\"16\")) text[2].setText(\"哈尼族\"); else if (nationStr.equals(\"17\")) text[2].setText(\"哈萨克族\"); else if (nationStr.equals(\"18\")) text[2].setText(\"傣族\"); else if (nationStr.equals(\"19\")) text[2].setText(\"黎族\");
else if (nationStr.equals(\"20\")) text[2].setText(\"傈僳族\"); else if (nationStr.equals(\"21\")) text[2].setText(\"佤族\"); else if (nationStr.equals(\"22\")) text[2].setText(\"畲族\"); else if (nationStr.equals(\"23\")) text[2].setText(\"高山族\"); else if (nationStr.equals(\"24\")) text[2].setText(\"拉祜族\"); else if (nationStr.equals(\"25\")) text[2].setText(\"水族\"); else if (nationStr.equals(\"26\")) text[2].setText(\"东乡族\"); else if (nationStr.equals(\"27\")) text[2].setText(\"纳西族\"); else if (nationStr.equals(\"28\")) text[2].setText(\"景颇族\"); else if (nationStr.equals(\"29\")) text[2].setText(\"柯尔克孜族\"); else if (nationStr.equals(\"30\")) text[2].setText(\"土族\"); else if (nationStr.equals(\"31\")) text[2].setText(\"达翰尔族\"); else if (nationStr.equals(\"32\")) text[2].setText(\"仫佬族\"); else if (nationStr.equals(\"33\")) text[2].setText(\"羌族\"); else if (nationStr.equals(\"34\")) text[2].setText(\"布朗族\"); else if (nationStr.equals(\"35\")) text[2].setText(\"撒拉族\"); else if (nationStr.equals(\"36\")) text[2].setText(\"毛南族\"); else if (nationStr.equals(\"37\")) text[2].setText(\"仡佬族\"); else if (nationStr.equals(\"38\")) text[2].setText(\"锡伯族\"); else if (nationStr.equals(\"39\")) text[2].setText(\"阿昌族\"); else if (nationStr.equals(\"40\")) text[2].setText(\"普米族\"); else if (nationStr.equals(\"41\")) text[2].setText(\"哈萨克族\"); else if (nationStr.equals(\"42\")) text[2].setText(\"怒族\"); else if (nationStr.equals(\"43\")) text[2].setText(\"乌孜别克族\"); else if (nationStr.equals(\"44\")) text[2].setText(\"俄罗斯族\"); else if (nationStr.equals(\"45\")) text[2].setText(\"鄂温克族\"); else if (nationStr.equals(\"46\"))
text[2].setText(\"德昂族\");
else if (nationStr.equals(\"47\"))
text[2].setText(\"保安族\");
else if (nationStr.equals(\"48\"))
text[2].setText(\"裕固族\");
else if (nationStr.equals(\"49\"))
text[2].setText(\"京族\");
else if (nationStr.equals(\"50\"))
text[2].setText(\"塔塔尔族\");
else if (nationStr.equals(\"51\"))
text[2].setText(\"独龙族\");
else if (nationStr.equals(\"52\"))
text[2].setText(\"鄂伦春族\");
else if (nationStr.equals(\"53\"))
text[2].setText(\"赫哲族\");
else if (nationStr.equals(\"54\"))
text[2].setText(\"门巴族\");
else if (nationStr.equals(\"55\"))
text[2].setText(\"珞巴族\");
else if (nationStr.equals(\"56\"))
text[2].setText(\"基诺族\");
else if (nationStr.equals(\"57\"))
text[2].setText(\"其它\");
else if (nationStr.equals(\"98\"))
text[2].setText(\"外国人入籍\");
String BirthyearStr = \"\";
char[] BirthyearChar = new char[4];
Info[1].getChars(3, 7, BirthyearChar, 0);
BirthyearStr = String.valueOf(BirthyearChar);
String BirthmonthStr = \"\";
char[] BirthmonthChar = new char[2];
Info[1].getChars(7, 9, BirthmonthChar, 0);
BirthmonthStr = String.valueOf(BirthmonthChar);
String BirthdateStr = \"\";
char[] BirthdateChar = new char[2];
Info[1].getChars(9, 11, BirthdateChar, 0);
BirthdateStr = String.valueOf(BirthdateChar);
text[3].setText(BirthyearStr + \"年\" + BirthmonthStr + \"月\" + BirthdateStr + \"日\");
char[] addreChar = new char[Info[1].length()18];
Info[2].getChars(18, Info[2].length(), iueChar, 0);
String iueStr = \"\";
iueStr = String.valueOf(iueChar);
text[6].setText(iueStr);
char[] startyearChar = new char[4];
Info[3].getChars(0, 4, startyearChar, 0);
String startyearStr = \"\";
startyearStr = String.valueOf(startyearChar);
char[] startmonthChar = new char[2];
Info[3].getChars(4, 6, startmonthChar, 0);
String startmonthStr = \"\";
startmonthStr = String.valueOf(startmonthChar);
char[] startdateChar = new char[2];
Info[3].getChars(6, 8, startdateChar, 0);
String startdateStr = \"\";
startdateStr = String.valueOf(startdateChar);
text[7].setText(startyearStr + \"年\" + startmonthStr + \"月\" + startdateStr + \"日\");
char[] endyearChar = new char[4];
Info[3].getChars(8, 12, endyearChar, 0);
String endyearStr = \"\";
endyearStr = String.valueOf(endyearChar);
char[] endmonthChar = new char[2];
Info[3].getChars(12, 14, endmonthChar, 0);
String endmonthStr = \"\";
endmonthStr = String.valueOf(endmonthChar);
char[] enddateChar = new char[2];
Info[3].getChars(14, 16, enddateChar, 0);
String enddateStr = \"\";
enddateStr = String.valueOf(enddateChar);
text[8].setText(endyearStr + \"年\" + endmonthStr + \"月\" + enddateStr + \"日\");
int count1 = d.getSize();
byte[] byteArray1 = new byte[count1];
for (i = 0; i
byteArray1[i] = c.getAsByte(i);
try {
File myFile = new File(\"zp.wlt\");
FileOutputStream out = new FileOutputStream(myFile);
out.write(byteArray1, 0, count1 - 1);
} catch (IOException t) {
}
closeJN.invoke();
// System.out.println(closeJN.getRetVal());
int l = 0;
System.loadLibrary(\"WltRS\");
BmpJN = new JNative(\"WltRS\", \"GetBmp\");
BmpJN.setRetVal(Type.INT);
BmpJN.setParameter(l++, \"zp.wlt\");
BmpJN.setParameter(l++, 1);
BmpJN.invoke();
if (readJN.getRetVal().equals(\"144\"))
System.out.println(\"相片解码成功!\");
else
System.out.println(\"相片解码不成功!\");
Image image = null;
try {
image = ImageIO.read(new File(\"zp.bmp\"));
} catch (IOException ex) {
}
ImageIcon icon = new ImageIcon(image);
showBmp.setIcon(icon);
getContentPane().add(showBmp);
setVisible(true);
a.dispose();
b.dispose();
c.dispose();
d.dispose();
e.dispose();
} catch (NativeException e) {
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
} catch (IllegalAcceException e) {
} }
public static void main(String agrs[]) {
InformationReader informationReader = new InformationReader(\"二代身份证信息读取\");
informationReader.setSize(500, 500); } }