Java spring boot 开发中控Live10R指纹采集器linux(指纹登录系统)

news/2024/10/23 9:31:05/

1.需求

   需要做一个指纹登录系统,录入指纹,修改指纹等,指纹比对等。

2.开发

    开启指纹采集器,指纹采集器base64数据录入到数据库以及指纹登录登出

package com.iot.modules.biz.fp;import com.iot.common.util.CommonUtil;
import com.iot.modules.biz.dao.FpMapper;
import com.iot.modules.biz.dao.UserMapper;
import com.iot.modules.biz.entity.Fp;
import com.iot.modules.biz.entity.User;
import com.iot.modules.biz.opc.OpcUaConfig;
import com.iot.modules.biz.quart.ScheduleFrontprocessService;
import com.iot.modules.biz.redis.RedisUtil;
import com.zkteco.biometric.FingerprintSensorErrorCode;
import com.zkteco.biometric.FingerprintSensorEx;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Service;@Configuration
@Slf4j
@Service
public class FpConfig {@AutowiredFpMapper fpMapper;//the width of fingerprint imageint fpWidth = 0;//the height of fingerprint imageint fpHeight = 0;//for verify testprivate byte[] lastRegTemp = new byte[2048];//the length of lastRegTempprivate int cbRegTemp = 0;//pre-register templateprivate byte[][] regtemparray = new byte[3][2048];//Registerprivate boolean bRegister = false;//Identifyprivate boolean bIdentify = true;//finger idprivate int iFid = 1;private int nFakeFunOn = 1;//must be 3static final int enroll_cnt = 3;//the index of pre-register functionprivate int enroll_idx = 0;private byte[] imgbuf = null;private byte[] template = new byte[2048];private int[] templateLen = new int[1];private boolean mbStop = true;private long mhDevice = 0;private long mhDB = 0;private WorkThread workThread = null;@Autowiredprivate RedisUtil redisUtil;@Autowiredprivate UserMapper userMapper;@AutowiredScheduleFrontprocessService scheduleFrontprocessService;@AutowiredOpcUaConfig opcUaConfig;@Beanpublic void actionPerformed() {// TODO Auto-generated method stubif (0 != mhDevice) {//already initedlog.error("请先关闭设备!");return;}int ret = FingerprintSensorErrorCode.ZKFP_ERR_OK;//InitializecbRegTemp = 0;bRegister = false;bIdentify = false;iFid = 1;enroll_idx = 0;if (FingerprintSensorErrorCode.ZKFP_ERR_OK != FingerprintSensorEx.Init()) {log.error("初始化失败!");;}ret = FingerprintSensorEx.GetDeviceCount();if (ret < 0) {log.error("未连接任何设备!");FreeSensor();return;}if (0 == (mhDevice = FingerprintSensorEx.OpenDevice(0))) {log.error("打开设备失败,状态! = " + ret + "!");FreeSensor();return;}if (0 == (mhDB = FingerprintSensorEx.DBInit())) {log.error("初始化数据库失败, 状态! = " + ret + "!");FreeSensor();return;}//set fakefun off//FingerprintSensorEx.SetParameter(mhDevice, 2002, changeByte(nFakeFunOn), 4);byte[] paramValue = new byte[4];int[] size = new int[1];//GetFakeOn//size[0] = 4;//FingerprintSensorEx.GetParameters(mhDevice, 2002, paramValue, size);//nFakeFunOn = byteArrayToInt(paramValue);size[0] = 4;FingerprintSensorEx.GetParameters(mhDevice, 1, paramValue, size);fpWidth = byteArrayToInt(paramValue);size[0] = 4;FingerprintSensorEx.GetParameters(mhDevice, 2, paramValue, size);fpHeight = byteArrayToInt(paramValue);//width = fingerprintSensor.getImageWidth();//height = fingerprintSensor.getImageHeight();imgbuf = new byte[fpWidth * fpHeight];mbStop = false;//  指纹线程workThread = new WorkThread();workThread.start();// 启动线程log.info("打开成功!");}@Servicepublic class WorkThread extends Thread {@SneakyThrows@Overridepublic void run() {super.run();int ret = 0;while (!mbStop) {templateLen[0] = 2048;if (0 == (ret = FingerprintSensorEx.AcquireFingerprint(mhDevice, imgbuf, template, templateLen))) {if (nFakeFunOn == 1) {byte[] paramValue = new byte[4];int[] size = new int[1];size[0] = 4;int nFakeStatus = 0;//GetFakeStatusret = FingerprintSensorEx.GetParameters(mhDevice, 2004, paramValue, size);nFakeStatus = byteArrayToInt(paramValue);System.out.println("ret = " + ret + ",nFakeStatus=" + nFakeStatus);if (0 == ret && (byte) (nFakeStatus & 31) != 31) {log.error("是假货吗?");return;}}String strBase64 = FingerprintSensorEx.BlobToBase64(template, templateLen[0]);Fp fp = fpMapper.selectById(1);fp.setFp(strBase64);fpMapper.updateById(fp);System.out.println("strBase64=" + strBase64);// 登录或者登出信号String saoMaDengLuTuiChu = redisUtil.pudReidsKeyObject("fycgplc01.saomadengludengchu").toString();if (saoMaDengLuTuiChu.equals("1.0") || saoMaDengLuTuiChu.equals("2.0")) {String onExtractOK = OnExtractOK(template, templateLen[0]);if (onExtractOK.equals("-17")) {opcUaConfig.writeOpcUa("saomadengludengchu", "0");continue;}if (onExtractOK.length() < 4) {onExtractOK = CommonUtil.intToBinary2(onExtractOK);}User user = userMapper.selectUserNumber(onExtractOK);// 登录if (saoMaDengLuTuiChu.equals("1.0")) {opcUaConfig.writeOpcUa("saomadengludengchu", "0");log.info("指纹登录成功!{}",user);scheduleFrontprocessService.authorityRepeat(user);}// 登出if (saoMaDengLuTuiChu.equals("2.0")) {opcUaConfig.writeOpcUa("saomadengludengchu", "0");log.info("指纹登出成功!{}",user);scheduleFrontprocessService.signOutAuthorityRepeat(user);}}}try {Thread.sleep(500);} catch (InterruptedException e) {e.printStackTrace();}}}private void runOnUiThread(Runnable runnable) {// TODO Auto-generated method stub}}private String OnExtractOK(byte[] template, int len) {int[] fid = new int[1];int[] score = new int[1];int ret = FingerprintSensorEx.DBIdentify(mhDB, template, fid, score);if (ret == 0) {return String.valueOf(fid[0]);} else {log.info("识别失败,错误码=" + ret);return String.valueOf(ret);}}private void FreeSensor() {mbStop = true;try {        //wait for thread stoppingThread.sleep(1000);} catch (InterruptedException e) {// TODO Auto-generated catch blocke.printStackTrace();}if (0 != mhDB) {FingerprintSensorEx.DBFree(mhDB);mhDB = 0;}if (0 != mhDevice) {FingerprintSensorEx.CloseDevice(mhDevice);mhDevice = 0;}FingerprintSensorEx.Terminate();}public static byte[] intToByteArray(final int number) {byte[] abyte = new byte[4];abyte[0] = (byte) (0xff & number);abyte[1] = (byte) ((0xff00 & number) >> 8);abyte[2] = (byte) ((0xff0000 & number) >> 16);abyte[3] = (byte) ((0xff000000 & number) >> 24);return abyte;}public static int byteArrayToInt(byte[] bytes) {int number = bytes[0] & 0xFF;number |= ((bytes[1] << 8) & 0xFF00);number |= ((bytes[2] << 16) & 0xFF0000);number |= ((bytes[3] << 24) & 0xFF000000);return number;}}

定时器循环更新指纹(需求  多个指纹采集器,一个录入采集器 ,一个比对采集器)

private long mhDB = 0;/*** 循环录入指纹*/@Scheduled(fixedRate = 30000)public void fpRealTimeEntry() {// 获取所有录入过指纹的打开后直接录入EntityWrapper entityWrapper = new EntityWrapper();entityWrapper.eq("device_type", "smt");entityWrapper.eq("status", "1");List<User> list = userMapper.selectList(entityWrapper);int ret = FingerprintSensorErrorCode.ZKFP_ERR_OK;if (0 == (mhDB = FingerprintSensorEx.DBInit())) {log.error("初始化数据库失败, 状态! = " + ret + "!");return;}for (User fp : list) {if (StringUtil.isNotBlank(fp.getFingerPrintBase64())) {String regTemps = fp.getFingerPrintBase64();int number = Double.valueOf(fp.getNumber()).intValue();byte[] decoded = Base64.decodeBase64(regTemps.getBytes());int i1 = FingerprintSensorEx.DBDel(mhDB, number);System.out.println("删除当前指纹"+i1);int i = FingerprintSensorEx.DBAdd(mhDB, number, decoded);System.out.println(i);}}}

3. 打包发布

   运行zkdemo注意环境的坑

Java环境配置:

export JAVA_HOME=/home/java/jdk1.8.0_291
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib:wq!// 刷新一下
source /etc/profile

 打jar包, 

 libs文件跟jar包同一目录

发布命令:  LD_LIBRARY_PATH=./libs nohup java -jar iot.jar &

4.完结:

 


http://www.ppmy.cn/news/328308.html

相关文章

中控消费机一直显示连接服务器,中控消费机培训及常见问题的解决办法-1.ppt

《人教版历史第14课灿烂的宋元文化二 培训主题 消费机功能基本操作介绍 CM20集消费机&#xff0c;出纳机&#xff0c;补贴机功能于一体。机器的操作&#xff0c;分为机器操作和软件操作两大块。其中可以通过机器操作来实现消费机/出纳机/补贴机之间的切换。软件界面简洁清晰、操…

中控消费机一直显示连接服务器,中控消费机培训及常见问题的解决办法课件.ppt...

培训主题 消费系统培训 消费机功能基本操作介绍 CM20集消费机 出纳机 补贴机功能于一体 机器的操作 分为机器操作和软件操作两大块 其中可以通过机器操作来实现消费机 出纳机 补贴机之间的切换 软件界面简洁清晰 操作方便 功能齐全 系统稳定可靠 大大提升了管理效率 机器硬件核…

中控人脸指纹考勤机怎么如何偷偷修改数据记录

中控人脸指纹考勤机怎么如何偷偷修改数据记录在日常工作中&#xff0c;由于公司、单位、企业安装使用了人脸考勤机或指纹打卡机&#xff0c;进行员工考勤签到打卡管理&#xff0c;所以&#xff0c;很多员工或职员&#xff0c;都会按时上下班&#xff0c;自觉签到签退。可以说人…

中控H10考勤机管理员密码破解

中控H10考勤机管理员密码破解 标签&#xff1a;考勤机 管理员 密码破解 1. 管理员破解方式 首先看考勤机上的时间&#xff0c;比如显示为20:24&#xff0c;去掉冒号为2024管理员密码为&#xff1a; (9999−2024)263600625 长按M/OK键&#xff0c;进入管理员界面&#xff0c;输…

中控指纹考勤机软件登录用户名和密码忘记的解决办法

原文&#xff1a;http://tieba.baidu.com/p/2035038238 首先计算机必须安装了Office2000&#xff08;要有access&#xff09;&#xff0c;然后进入考勤程序安装目录&#xff0c;找到Att2000.mdb文件&#xff0c;双击打开&#xff0c;在出现的界面中找到userinfo表&#xff0c;双…

考勤 指纹 php,折腾中控指纹签到SDK始末(.net监听) | quericy Eden*

Reflector 先尝试 1copy .\*.dll %windir%\System32\ 2regsvr32 %windir%\System32\zkemkeeper.dll 我就不吐槽官方的包把system32写成小写了… 然后看看Demo…有P/Invoke的全称是Platform Invoke (平台调用) 它实际上是一种函数调用机制,通过P/Invoke可以调用非托管DLL中的函数…

中控太科--指纹机

http://www.zkteco.cn/cp/class/?5.html

中控消费机一直显示连接服务器,中控消费机培训及常见问题的解决办法

《中控消费机培训及常见问题的解决办法》由会员分享&#xff0c;可在线阅读&#xff0c;更多相关《中控消费机培训及常见问题的解决办法(28页珍藏版)》请在人人文库网上搜索。 1、用拼搏的精神做事业 用感恩的心做人用拼搏的精神做事业 用感恩的心做人 把握科技高端共赢识别市场…