华视电子web读取身份证信息
首先的是加入要引用的dll文件,放到需要使用的电脑的位置,我的是
E:/soft/labor/Termb.dll
然后看congtroller层的代码是:
import com.exa.dem.entity.CPReadIdCardInfoModel; import com.exa.dem.service.CPReadIdCardInfoService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController;@RestController public class testController {@AutowiredCPReadIdCardInfoService service;@GetMapping("/card")public String test() throws Exception {CPReadIdCardInfoModel infoModel = service.readIdCardInfo();String code = infoModel.getCode();return code;} }
然后是service层的两个类入下:
import com.sun.jna.Library; import com.sun.jna.Native; import com.sun.jna.ptr.IntByReference;public interface TermbDLL extends Library {// termb.dll API函数的动态联接库// sdtapi.dll 安全模块通讯函数// WltRs.dll 身份证相片解码库//TermbDLL termbDLL = (TermbDLL) Native.loadLibrary("E:/soft/labor/dem/src/main/resources/Termb.dll", TermbDLL.class); // jar包代码 /E:/soft/labor/Termb.dllTermbDLL termbDLL = (TermbDLL) Native.loadLibrary("E:/soft/labor/Termb.dll", TermbDLL.class);/*** 连接读卡器*/int CVR_InitComm(int Port);/*** 卡认证*/int CVR_Authenticate();/*** 读卡*/int CVR_Read_Content(int active);/*** 读卡操作 含指纹*/int CVR_Read_FPContent(int active);/*** 关闭连接*/int CVR_CloseComm();/*** 找卡*/int CVR_FindCard();/*** 选卡*/int CVR_SelectCard();/*** 获取姓名*/int GetPeopleName(byte[] name, IntByReference len);/*** 得到性别信息*/int GetPeopleSex(byte[] sex, IntByReference len);/*** 得到民族信息*/int GetPeopleNation(byte[] strTmp, IntByReference strLen);/*** 得到出生日期*/int GetPeopleBirthday(byte[] strTmp, IntByReference strLen);/*** 得到地址信息*/int GetPeopleAddress(byte[] strTmp, IntByReference strLen);/*** 得到身份证号信息**/int GetPeopleIDCode(byte[] strTmp, IntByReference strLen);/*** 得到发证机关信息*/int GetDepartment(byte[] strTmp, IntByReference strLen);/*** 得到有效开始日期*/int GetStartDate(byte[] strTmp, IntByReference strLen);/*** 得到有效截止日期*/int GetEndDate(byte[] strTmp, IntByReference strLen);/*** 得到安全模块号*/int CVR_GetSAMID(byte[] strTmp);/*** 得到指纹数据,不超过1024字节*/int GetFPDate(byte[] strTmp, IntByReference strLen);/*** 得到头像照片bmp数据,不超过38862字节*/int GetBMPData(byte[] strTmp, IntByReference strLen);/*** 得到头像照片base64编码数据,不超过38862*2字节*/int Getbase64BMPData(byte[] strTmp, IntByReference strLen);/*** 得到头像照片jpg数据,不超过38862字节*/int Getbase64JpgData(byte[] strTmp, IntByReference strLen);}
另一个类是如下:
import com.exa.dem.entity.CPReadIdCardInfoModel; import com.sun.jna.Native; import com.sun.jna.ptr.IntByReference; import org.springframework.stereotype.Service; import org.springframework.util.StringUtils;import java.io.UnsupportedEncodingException; import java.lang.reflect.Method; import java.net.URL; import java.util.concurrent.TimeUnit;@Service public class CPReadIdCardInfoService {//成功状态码private static final int SUCCESS = 1;//失败状态码private static final int FAIL = 0;private static final String CHARACTER_ENCODING = "gb2312";public CPReadIdCardInfoModel readIdCardInfo() throws Exception {CPReadIdCardInfoModel readIdCardInfoModel = new CPReadIdCardInfoModel();TermbDLL instance = buildInstance();try {connAndCheckDevice(instance);//读取身份证各信息IntByReference len = new IntByReference();//1、姓名String name = getPeopleName(instance, len);//2、性别String sex = getPeopleSex(instance,len);String code = GetPeopleIDCode(instance,len);readIdCardInfoModel.setName(name);readIdCardInfoModel.setSex(sex);readIdCardInfoModel.setCode(code);return readIdCardInfoModel;} finally {instance.CVR_CloseComm();}}private String getPeopleName(TermbDLL instance, IntByReference len) {try {//长度更具华视文档设定byte [] nameStrTmp = new byte[30];//JNA调用DLL方法instance.GetPeopleName(nameStrTmp,len);return handleResult(nameStrTmp);} catch (Exception e) {e.printStackTrace();}return null;}private String getPeopleSex(TermbDLL instance, IntByReference len) {try {byte [] sexStrTmp = new byte[2];instance.GetPeopleSex(sexStrTmp,len);return handleResult(sexStrTmp);} catch (Exception e) {e.printStackTrace();}return null;}/*** 身份证* @param instance* @param strLen* @return*/private String GetPeopleIDCode(TermbDLL instance, IntByReference strLen){try {byte [] sexStrTmp = new byte[50];instance.GetPeopleIDCode(sexStrTmp,strLen);return handleResult(sexStrTmp);} catch (Exception e) {e.printStackTrace();}return null;}private String getPeopleInfo(TermbDLL instance, String methodName, IntByReference len) {try {byte [] strTmp = new byte[10];Method method = instance.getClass().getMethod(methodName, byte[].class, IntByReference.class);method.invoke(instance,strTmp,len);return handleResult(strTmp);} catch (Exception e) {e.printStackTrace();}return null;}private String handleResult(byte[] nameByte) throws UnsupportedEncodingException {//处理返回值防止乱码return new String(nameByte, CHARACTER_ENCODING).trim();}private void connAndCheckDevice(TermbDLL instance) throws Exception {//1、初始化连接cvrInitComm(instance);//2、读卡(同一个身份证,只要读取一次,下次读取优先从缓存中读取,并且CVR_Authenticate返回为2,卡认证失败,所以优先读卡一次)int readStatus = instance.CVR_Read_Content(1); //读取卡//2、卡认证,超出两分钟就是本次读卡失败int authenticate = getAuthenticateStatus(instance, readStatus);if (authenticate != SUCCESS)throw new Exception("读卡失败,请重新放置卡片");if (readStatus != SUCCESS)readStatus = instance.CVR_Read_Content(1); //读取卡if (readStatus != SUCCESS)throw new Exception("证件信息读取失败,请重新放置证件");}/*** 卡认证* @param instance DLL* @param readStatus 同一个身份证,只要读取一次,下次读取优先从缓存中读取,并且CVR_Authenticate返回为2,卡认证失败,所以优先读卡一次*/private int getAuthenticateStatus(TermbDLL instance, int readStatus) throws InterruptedException {if (readStatus == SUCCESS)return SUCCESS;final long deadline = System.nanoTime() + TimeUnit.MINUTES.toNanos(2L);int authenticate = FAIL;//循环读卡,失效时间为2分钟while (authenticate != SUCCESS){authenticate = instance.CVR_Authenticate();if (deadline ==SUCCESS)continue;if (deadline - System.nanoTime()<0L)break;Thread.sleep(100);//短暂休眠}return authenticate;}private void cvrInitComm(TermbDLL instance) throws Exception {int cvrInitComm = instance.CVR_InitComm(1001);if (cvrInitComm != SUCCESS){throw new Exception("读卡器连接失败,请检查设备状态");}}private TermbDLL buildInstance() throws Exception {//String dllPath = "/E:/soft/labor/dem/src/main/resources/Termb.dll";String dllPath = "E:/soft/labor/Termb.dll";if (StringUtils.isEmpty(dllPath)) { throw new Exception("请检查设备状态"); }if (StringUtils.startsWithIgnoreCase(dllPath,"/")){dllPath = dllPath.substring(1);}try {return (TermbDLL) Native.loadLibrary(dllPath, TermbDLL.class);} catch (Exception e) {throw new Exception("请检查设备状态");}} }
实体类入下:
import lombok.Data;@Data public class CPReadIdCardInfoModel {private String name;private String sex;private String code; }
然后通过js调用controller层的代码,就可以获得身份证的相关信息了。
还需要的dll文件是 WltRS.dll,sdtapi.dll 加上开头的dll文件总共三个。
华视电子web读取身份证信息相关推荐
- web读取身份证信息(java语言)
其实实现读取身份证信息,代码其实没有多难,关键需要和硬件的厂商协调好,看他们的硬件是否支持二次开发(一般都支持).如果支持我们需要和他们拿到他们底层的jar包和api(接口文档),要是有demo就更好 ...
- 浏览器使用华视电子设备读取身份证信息
前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家. 对人工智能感兴趣或者想了解的小伙伴,可以点击跳转到网站一起学习哟. https://www.captainai.ne ...
- 华视电子vue身份证读取
一.华视电子官网下载程序包 官网地址 二.安装 安装Windows程序安装完成以后会在文件夹内自动生成一个(100UD开发包(Windows))开发包文件夹 打开此文件夹 打开USB驱动安装64位操作 ...
- 基于华视身份证读卡器读取身份证信息的Android demo
项目概述 本Demo需要华视的身份证读卡器,连接Android机器设备,当身份证读卡器读取到身份证信息后,立马展示出身份证信息数据.得到身份证的姓名.照片.出生年月等数据. 项目概述 本Demo需要华 ...
- VUE实现华视身份证阅读器读取身份证信息
VUE实现华视身份证阅读器读取身份证信息 话不多上直接上代码,写的不怎么规范多多包涵,我是在模态框实现的,在这里就只提供模态框代码. 最后附上华视身份证阅读器安装文件和浏览器插件链接: [https: ...
- VUE实现华视身份证阅读器读取身份证信息(本文分两种情况,第一中是点击按钮读取信息,一种是自动读取信息)
本文是用了vue+element来实现华视身份证读卡器读取身份信息的,当然在开发之前要做好前提准备,就是厂家提供对应设备的api和安装对应的驱动.本文通过两种方法来实现读取信息,第一种是点击按钮读取信 ...
- Java CRV-100UC华视电子身份证读卡器二次开发
准备工作: 环境:windows.jdk(32bit) 华视SDK开发包: sdtapi.dll(函数的动态联接库) Termb.dll(安全模块通讯函数) WltRS.dll(身份证相片解码库) J ...
- 使用jnative调用c语言动态库对接华视电子身份证阅读机
一 身份证阅读器SDK使用手册 1. 定义 应用函数开发包含下列文件: termb.dll API函数的动态联接库 sdtapi.dll 安全模块通讯函数 UnPack.dll 身份证相片解码库 适用 ...
- vue调用华视电子身份证阅读器cvr-100uc
1.去官网下载安装包服务下载_华视电子 解压后点击 安装后找到网页版开发包 点击华视电子读卡器安装,安装后点击读卡服务 安装USB插件. 2.新建reader.js文件,阅读器默认端口19196 3. ...
最新文章
- 号召,有兴趣做博客园自己的网络游戏的请举手..
- [20180428]DNS与ORA-12154错误.txt
- [Luogu1891]疯狂LCM[辗转相减法]
- firefox android 去更新,Android版Firefox Beta发布更新
- python po设计模式_Python Selenium设计模式 - PO设计模式
- 8902382_52671.jpg
- Java之品优购课程讲义_day20(2)
- python基础之字典、集合
- 服务器里怎么设置微信多开,企业微信多开的4种方法
- 手机内存文件夹html,手机内存难清理?试试直接删掉这3个文件夹,网友:咋不早说?...
- 自动化测试框架[Cypress概述]
- 服务器系统2008恢复,win2003升级为win2008、win2012保留数据重装恢复数据说明
- python实现决策树 西瓜书_朴素贝叶斯python代码实现(西瓜书)
- LintCode 138.子数组之和
- 2018年银联红包领取方法
- 在家谱中查找关系远近
- 重置计算机网络配置后上不了网,路由器重置后上不了网怎么办 怎么重新设置路由器...
- xmanager 5 linux 6.5,工欲善其事必先利其器 —— Xmanager Enterprise 5 和 RealVNC 5/6 介绍...
- cp7s2装Linux,基礎級拆機-神舟戰神GX8CP5s1上8700發現較為雞肋-仿CP7s2
- 视频解读:案例透视消费者洞察实践与收益