java连接 ZKTeco/中控 -打卡机/考勤机

04-18 1345阅读

 连接步骤:

1. jacob-1.19版本;

2. 在resources目录下新建lib文件夹, 将jacob.jar 放入项目ib导入;

3. maven里导入本地jar包;

4.将jacob-1.19-x64.dll 放入64位 jre/bin目录下;

5.将中控考勤机sdk 的dll文件全部放入 c:\windows\system32 目录下;

6.运行cmd 注册zkemkeeper.dll —>regsvr32 c:\windows\system32\zkemkeeper.dll (也可以使用 自动注册.bat,不行的话就要放在64位里面)

7.已经配置完毕,进行代码测试;

我看了很多的文章,在这里有一个坑就是zkemkeeper.dll文件没有,这个的话就需要你找客服去要,(客服有可能给的也是错的,就要找客服给技术人员,你就找技术人员去要)而且还没人分享出来,下面就是我分享出来的 jacob-1.19.jar下载和控考勤机sdk

链接:java链接考勤机java连接 ZKTeco/中控 -打卡机/考勤机https://wwtx.lanzout.com/b04w8t9ra

提取码:asawwqe

 转java连接 ZKTeco/中控 -打卡机/考勤机_zkteco java-CSDN博客java连接 ZKTeco/中控 -打卡机/考勤机https://blog.csdn.net/qq_58320145/article/details/132190661

开始教程

1.

将jacob-1.19.dll放入jdk1.8中的bin

java连接 ZKTeco/中控 -打卡机/考勤机

java连接 ZKTeco/中控 -打卡机/考勤机

java连接 ZKTeco/中控 -打卡机/考勤机

 找到这个jar把他复制到java连接 ZKTeco/中控 -打卡机/考勤机

新建一个lib然后放进去

java连接 ZKTeco/中控 -打卡机/考勤机

 这个代码是调用自己的lib中的jar包

        
            com.zkem
            jacob
            1.19
            system
            ${project.basedir}/src/main/resources/lib/jacob.jar
        

这样就配置好了jacob.jar包了

1-1.

还有一个就是部署到服务器中就访问不到的一个问题

java连接 ZKTeco/中控 -打卡机/考勤机

其他的不总要,只要吧enabled设置位true就可以了,说的就是访问自己的lib

            
                true
            

2

下面就是将文件复制到c:\windows\system32和c:\windows\system64中,最重要的是记得注册zkemkeeper.dll

注册方法 在 zkemkeeper.dll文件夹的路径输入cmd,在命令窗口输入  regsvr32 zkemkeeper.dll

就可以进行注册

java连接 ZKTeco/中控 -打卡机/考勤机

java连接 ZKTeco/中控 -打卡机/考勤机java连接 ZKTeco/中控 -打卡机/考勤机

注册dll 

 java连接 ZKTeco/中控 -打卡机/考勤机

java连接 ZKTeco/中控 -打卡机/考勤机

java连接 ZKTeco/中控 -打卡机/考勤机

java连接 ZKTeco/中控 -打卡机/考勤机

 3.

下面就是主要的代码部分了

实体类

package com.ruoyi.web.attendanceMachine;
import java.util.Map;
/**
 * 获取缓存中的考勤数据。配合readGeneralLogData / readLastestLogData使用。
 *      *
 *      * @return 返回的map中,包含以下键值:
 *      * "EnrollNumber"   人员编号
 *      * "Time"           考勤时间串,格式: yyyy-MM-dd HH:mm:ss
 *      * "VerifyMode"     验证方式  1:指纹 2:面部识别
 *      * "InOutMode"      考勤状态 0:上班 1:下班 2:外出 3:外出返回 4:加班签到 5:加班签退
 *      * "Year"          考勤时间:年
 *      * "Month"         考勤时间:月
 *      * "Day"           考勤时间:日
 *      * "Hour"            考勤时间:时
 *      * "Minute"        考勤时间:分
 *      * "Second"        考勤时间:秒
 *
 */
public class LogData {
    private String Year;
    private String Hour;
    private String InOutMode;
    private String Time;
    private String InOutMode1;
    private String Second;
    private String Minute;
    private String EnrollNumber;
    private String Day;
    private String Month;
    private String VerifyMode;
    private String Hms;
    public Map userInfo;
    public LogData(String year, String hour, String inOutMode, String time, String inOutMode1, String second, String minute, String enrollNumber, String day, String month, String verifyMode) {
        Year = year;
        Hour = hour;
        InOutMode = inOutMode;
        Time = time;
        InOutMode1 = inOutMode1;
        Second = second;
        Minute = minute;
        EnrollNumber = enrollNumber;
        Day = day;
        Month = month;
        VerifyMode = verifyMode;
    }
    public Map  getUserInfo() {
        return userInfo;
    }
    public void setUserInfo(Map  userInfo) {
        this.userInfo = userInfo;
    }
    public String getYear() {
        return Year;
    }
    public String getHms() {
        return Hms;
    }
    public void setHms(String hms) {
        Hms = hms;
    }
    public void setYear(String year) {
        Year = year;
    }
    public String getHour() {
        return Hour;
    }
    public void setHour(String hour) {
        Hour = hour;
    }
    public String getInOutMode() {
        return InOutMode;
    }
    public void setInOutMode(String inOutMode) {
        InOutMode = inOutMode;
    }
    public String getTime() {
        return Time;
    }
    public void setTime(String time) {
        Time = time;
    }
    public String getInOutMode1() {
        return InOutMode1;
    }
    public void setInOutMode1(String inOutMode1) {
        InOutMode1 = inOutMode1;
    }
    public String getSecond() {
        return Second;
    }
    public void setSecond(String second) {
        Second = second;
    }
    public String getMinute() {
        return Minute;
    }
    public void setMinute(String minute) {
        Minute = minute;
    }
    public String getEnrollNumber() {
        return EnrollNumber;
    }
    public void setEnrollNumber(String enrollNumber) {
        EnrollNumber = enrollNumber;
    }
    public String getDay() {
        return Day;
    }
    public void setDay(String day) {
        Day = day;
    }
    public String getMonth() {
        return Month;
    }
    public void setMonth(String month) {
        Month = month;
    }
    public String getVerifyMode() {
        return VerifyMode;
    }
    public void setVerifyMode(String verifyMode) {
        VerifyMode = verifyMode;
    }
    public LogData(){
    }
};
package com.ruoyi.web.attendanceMachine;
import com.jacob.com.Variant;
public class UserInfo {
    private String name;
    private Boolean Enabled;
    private String Password;
    private Integer Privilege;
    private String EnrollNumber;
    public Variant zw;
    public UserInfo(String name, Boolean enabled, String password, Integer privilege, String enrollNumber) {
        this.name = name;
        Enabled = enabled;
        Password = password;
        Privilege = privilege;
        EnrollNumber = enrollNumber;
    }
    public Variant getZw() {
        return zw;
    }
    public void setZw(Variant zw) {
        this.zw = zw;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public Boolean getEnabled() {
        return Enabled;
    }
    public void setEnabled(Boolean enabled) {
        Enabled = enabled;
    }
    public String getPassword() {
        return Password;
    }
    public void setPassword(String password) {
        Password = password;
    }
    public Integer getPrivilege() {
        return Privilege;
    }
    public void setPrivilege(Integer privilege) {
        Privilege = privilege;
    }
    public String getEnrollNumber() {
        return EnrollNumber;
    }
    public void setEnrollNumber(String enrollNumber) {
        EnrollNumber = enrollNumber;
    }
    public UserInfo(){};
}

 监听模块

package com.ruoyi.web.attendanceMachine;
import com.jacob.com.Variant;
import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.system.service.IUserinfoService;
import com.ruoyi.web.controller.mmt.UserinfoController;
import org.springframework.beans.factory.annotation.Autowired;
import com.ruoyi.system.domain.Userinfo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@DataSource(value = DataSourceType.MASTER)
public class SensorEvents {
	public IUserinfoService userinfoService;
	public void OnConnected(Variant[] arge){
		System.out.println("当成功连接机器时触发该事件,无返回值====");
	}
	public void OnDisConnected(Variant[] arge){
		System.out.println("当断开机器时触发该事件,无返回值====");
	}
	public void OnAlarm(Variant[] arge){
		System.out.println("当机器报警时触发该事件===="+arge);
	}
	public void OnAttTransactionEx(Variant[] arge){
		System.out.println("id:"+arge[0]);
		System.out.println("是否有效:0有效 1无效"+arge[1]);
		System.out.println("考勤状态:0 上班 1下班 2外出 3外出返回 4 加班签到 5 加班签退...."+arge[2]);
		System.out.println("验证方式 0:密码  1;指纹 15:刷脸认证"+arge[3]);
		System.out.println("验证时间"+arge[4]+"-"+arge[5]+"-"+arge[6]+"-"+arge[7]+":"+arge[8]+":"+arge[9]+" "+arge[10]);
		/*for (int i = 0; i  

实现代码

package com.ruoyi.web.attendanceMachine;
import com.alibaba.fastjson2.JSON;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.DispatchEvents;
import com.jacob.com.STA;
import com.jacob.com.Variant;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.Userinfo;
import com.ruoyi.system.service.IUserinfoService;
import com.ruoyi.web.controller.mmt.Main;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
/**
 * 中控考勤机sdk函数调用类
 * @author wangchao
 *
 */
public class ZkemSDK {
	private static ActiveXComponent zkem = new ActiveXComponent("zkemkeeper.ZKEM.1");
	private Fingerprint fingerprint = null;
	/**
	 * 链接考勤机
	 *
	 * @param address 考勤机地址
	 * @param port    端口号
	 * @return
	 */
	public boolean connect(String address, int port) {
		boolean result = zkem.invoke("Connect_NET", address, port).getBoolean();
		return result;
	}
	/**
	 * 断开考勤机链接
	 */
	public void disConnect() {
		zkem.invoke("Disconnect");
	}
	/**
	 * 读取考勤记录到pc缓存。配合getGeneralLogData使用
	 *
	 * @return
	 */
	public static boolean readGeneralLogData() {
		boolean result = zkem.invoke("ReadGeneralLogData", 4).getBoolean();
		return result;
	}
	/**
	 * 读取该时间之后的最新考勤数据。 配合getGeneralLogData使用。//网上说有这个方法,但是我用的开发文档没有这个方法,也调用不到,我在controller中处理获取当天数据
	 *
	 * @param lastest
	 * @return
	 */
	public static boolean readLastestLogData(Date lastest) {
		boolean result = zkem.invoke("ReadLastestLogData", 2018 - 07 - 24).getBoolean();
		return result;
	}
	/**
	 * 获取缓存中的考勤数据。配合readGeneralLogData / readLastestLogData使用。
	 *
	 * @return 返回的map中,包含以下键值:
	 * "EnrollNumber"   人员编号
	 * "Time"           考勤时间串,格式: yyyy-MM-dd HH:mm:ss
	 * "VerifyMode"     验证方式  1:指纹 2:面部识别
	 * "InOutMode"      考勤状态 0:上班 1:下班 2:外出 3:外出返回 4:加班签到 5:加班签退
	 * "Year"          考勤时间:年
	 * "Month"         考勤时间:月
	 * "Day"           考勤时间:日
	 * "Hour"            考勤时间:时
	 * "Minute"        考勤时间:分
	 * "Second"        考勤时间:秒
	 */
	public static List getGeneralLogData() {
		Variant dwMachineNumber = new Variant(1, true);//机器号
		Variant dwEnrollNumber = new Variant("", true);
		Variant dwVerifyMode = new Variant(0, true);
		Variant dwInOutMode = new Variant(0, true);
		Variant dwYear = new Variant(0, true);
		Variant dwMonth = new Variant(0, true);
		Variant dwDay = new Variant(0, true);
		Variant dwHour = new Variant(0, true);
		Variant dwMinute = new Variant(0, true);
		Variant dwSecond = new Variant(0, true);
		Variant dwWorkCode = new Variant(0, true);
		List strList = new ArrayList();
		boolean newresult = false;
		do {
			Variant vResult = Dispatch.call(zkem, "SSR_GetGeneralLogData", dwMachineNumber, dwEnrollNumber, dwVerifyMode, dwInOutMode, dwYear, dwMonth, dwDay, dwHour, dwMinute, dwSecond, dwWorkCode);
			newresult = vResult.getBoolean();
			if (true) {
				String enrollNumber = dwEnrollNumber.getStringRef();
				//如果没有编号,则跳过。
				// if (enrollNumber == null || enrollNumber.trim().length() == 0)
				// continue;
				String month = dwMonth.getIntRef() + "";
				String day = dwDay.getIntRef() + "";
				if (dwMonth.getIntRef()  -1) {
				name = name.substring(0, index);
			}
			if (sName.getStringRef().length() > 4) {
				name = sName.getStringRef().substring(0, 4);
			}
			//如果没有名字,跳过。
			if (name.trim().length() == 0)
				continue;
			UserInfo userInfo = new UserInfo();
			userInfo.setEnrollNumber(enrollNumber);
			userInfo.setName(name);
			userInfo.setPassword(sPassword.getStringRef());
			userInfo.setPrivilege(iPrivilege.getIntRef());
			userInfo.setEnabled((Boolean) bEnabled.getBooleanRef());
			userInfoList.add(userInfo);
		}
		return userInfoList;
	}
	/**
	 * 设置用户信息
	 *
	 * @param number
	 * @param name
	 * @param password
	 * @param isPrivilege 0為普通用戶,3為管理員;
	 * @param enabled     是否啟用
	 * @return
	 */
	public static boolean setUserInfo(String number, String name, String password, int isPrivilege, boolean enabled) {
		Variant v0 = new Variant(1);
		Variant sdwEnrollNumber = new Variant(number, true);
		Variant sName = new Variant(name, true);
		Variant sPassword = new Variant(password, true);
		Variant iPrivilege = new Variant(isPrivilege, true);
		Variant bEnabled = new Variant(enabled, true);
		boolean result = zkem.invoke("SSR_SetUserInfo", v0, sdwEnrollNumber, sName, sPassword, iPrivilege, bEnabled).getBoolean();
		return result;
	}
	/**
	 * 获取用户信息
	 *
	 * @param number 考勤号码
	 * @return
	 */
	public static Map getUserInfoByNumber(String number) {
		Variant v0 = new Variant(1);
		Variant sdwEnrollNumber = new Variant(number, true);
		Variant sName = new Variant("", true);
		Variant sPassword = new Variant("", true);
		Variant iPrivilege = new Variant(0, true);
		Variant bEnabled = new Variant(false, true);
		boolean result = zkem.invoke("SSR_GetUserInfo", v0, sdwEnrollNumber, sName, sPassword, iPrivilege, bEnabled).getBoolean();
		if (result) {
			Map m = new HashMap();
			m.put("EnrollNumber", number);
			m.put("Name", sName.getStringRef());
			m.put("Password", sPassword.getStringRef());
			m.put("Privilege", iPrivilege.getIntRef());
			m.put("Enabled", bEnabled.getBooleanRef());
			return m;
		}
		return null;
	}
	/**
	 * 获取用户信息
	 *
	 * @param number 考勤号码
	 * @return
	 */
	public static String getUserInfoByName(String number) {
		Variant v0 = new Variant(1);
		Variant sdwEnrollNumber = new Variant(number, true);
		Variant sName = new Variant("", true);
		Variant sPassword = new Variant("", true);
		Variant iPrivilege = new Variant(0, true);
		Variant bEnabled = new Variant(false, true);
		boolean result = zkem.invoke("SSR_GetUserInfo", v0, sdwEnrollNumber, sName, sPassword, iPrivilege, bEnabled).getBoolean();
		System.out.println(sName+"-"+sPassword+"-"+iPrivilege+"-"+bEnabled);
		return sName.getStringRef();
	}
	public static Userinfo getUserInfoByNames(Userinfo userinfo) {
		Variant v0 = new Variant(1);
		Variant sdwEnrollNumber = new Variant(userinfo.getEnrollNumber(), true);
		Variant sName = new Variant("", true);
		Variant sPassword = new Variant("", true);
		Variant iPrivilege = new Variant(0, true);
		Variant bEnabled = new Variant(false, true);
		boolean result = zkem.invoke("SSR_GetUserInfo", v0, sdwEnrollNumber, sName, sPassword, iPrivilege, bEnabled).getBoolean();
		userinfo.setEnrollNumber(String.valueOf(sdwEnrollNumber));
		userinfo.setName(String.valueOf(sName));
		userinfo.setPassword(String.valueOf(sPassword));
		return userinfo;
	}
	//获取指纹
	public static Variant GetUserTmpStr(String i) {
		Variant v0 = new Variant(1);
		byte temp = 0;
		Variant b = new Variant(i, true);
		Variant c = new Variant(1, true);
		Variant d = new Variant("", true);
		Variant e = new Variant(0, true);
/*    Variant dwMachineNumber = new Variant(0, true);//机器号
      Variant dwEnrollNumber = new Variant(0, true);//用户号
      Variant dwFingerIndex = new Variant(0, true);//指纹索引号
      Variant TmpData = new Variant(0, true);//该参数返回指纹模板数据
      Variant TmpLength = new Variant(0, true);//该参数返回指纹模板长度*/
		boolean result = zkem.invoke("SSR_GetUserTmpStr",v0, b, c, d,e).getBoolean();
		System.out.println("1:"+d.toString());
		System.out.println("2:"+result);
		return d;
	}
//上传指纹
	public static void SetUserTmpStr(String x,Variant d) {
		Variant v0 = new Variant(1);
		Variant a = new Variant(x, true);
		Variant b = new Variant(2, true);
		Variant c = d;
/*    Variant dwMachineNumber = new Variant(0, true);//机器号
      Variant dwEnrollNumber = new Variant(0, true);//用户号
      Variant dwFingerIndex = new Variant(0, true);//指纹索引号
      Variant TmpData = new Variant(0, true);//该参数返回指纹模板数据
      Variant TmpLength = new Variant(0, true);//该参数返回指纹模板长度*/
		boolean result = zkem.invoke("SSR_SetUserTmpStr", v0, a, b, c).getBoolean();
		System.out.println("3:"+c.toString());
		System.out.println("4:"+result);
	}
//删除
	public static void ReadAllTemplate() {
		Variant v0 = new Variant(1);
   // Variant dwMachineNumber = new Variant(0, true);//机器号
      Variant dwEnrollNumber = new Variant("1", true);//用户号
      Variant dwFingerIndex = new Variant(6, true);//指纹索引号
    //  Variant TmpData = new Variant(0, true);//该参数返回指纹模板数据
    //  Variant TmpLength = new Variant(0, true);//该参数返回指纹模板长度
		boolean result = zkem.invoke("SSR_DelUserTmp", v0,dwEnrollNumber,dwFingerIndex).getBoolean();
	}
	/**
	 * 查詢所有/指定ID的打卡信息;
	 *
	 * @param userNumber
	 * @return
	 */
	public static List getUserOneDayInfo(Object userNumber) {
		ZkemSDK sdk = new ZkemSDK();
		Map userInfo = new HashMap();
		List logDateList = new ArrayList();
		//连接考勤机;
		boolean connect = sdk.connect("192.168.1.189", 4370);
		if (connect) {
			List generalLogDataAll = ZkemSDK.getGeneralLogData();
			for (int i = 0; i  

java连接 ZKTeco/中控 -打卡机/考勤机

而这个是中控提供的方法 

好的,你已经完成了配置 考勤机/打卡机了

希望可以可怜可怜我给一个三连吧

转 java连接 ZKTeco/中控 -打卡机/考勤机_zkteco java-CSDN博客java连接 ZKTeco/中控 -打卡机/考勤机https://blog.csdn.net/qq_58320145/article/details/132190661

VPS购买请点击我

文章版权声明:除非注明,否则均为主机测评原创文章,转载或复制请以超链接形式并注明出处。

目录[+]