1,海康威视门禁设备对接海康SDK,集成封装相关代码,适配海康门禁人脸门禁一体机,目前版本为海康智能身份识别终端DS-K1T系列,其他系列根据官网描述也能适配,实际情况还需独子对接设备测试
2,目前完成相关功能集成,作为一个独立maven项目实现,可以打为jar包引入项目即可使用(该代码是根据业务需求所拟,故可根据实际需求更改jar代码…)
3,其中实现了:人员人脸,卡号,指纹(下发,删除,修改),门禁事件告警(设备),门禁异常告警,远程开关门,控制设备采集人脸,指纹。以及一些重要配置
4,代码有点low,但是功能基本实现,实际对接可互相交流一下。以下展示部分实现代码。
5,SDK加载
/*** 根据不同操作系统选择不同的库文件和库路径** @param windowsPath 库文件加载地址Windows环境* @param linuxPath 库文件加载地址linux环境* @return*/private static boolean createSdkInstance(String windowsPath, String linuxPath) {if (hCNetSDK == null) {synchronized (HCNetSDK.class) {String strDllPath = "";try {if (OsSelect.isWindows()) {//win系统加载库路径System.getProperty("user.dir")strDllPath = windowsPath + "\\HCNetSDK.dll";} else if (OsSelect.isLinux()) {//Linux系统加载库路径strDllPath = linuxPath + "/libhcnetsdk.so";}hCNetSDK = (HCNetSDK) Native.loadLibrary(strDllPath, HCNetSDK.class);} catch (Exception ex) {System.out.println("loadLibrary: " + strDllPath + " Error: " + ex.getMessage());ex.printStackTrace();return false;}}}return true;}
6,还需要进行初始化,才能进行设备登录
/*** 初始化NET_DVR_Init接口在程序开始时调用,一个程序只需要调用一次。** @param windowsPath 库文件加载地址Windows环境* @param linuxPath 库文件加载地址Linu环境* @return*/public static BackResult initInformation(String windowsPath, String linuxPath) {BackResult backResult = new BackResult();if (hCNetSDK == null) {if (!createSdkInstance(windowsPath, linuxPath)) {backResult.setStatusCode(11);backResult.setStatusCodeMsg("Load SDK fail");return backResult;}}//linux系统建议调用以下接口加载组件库if (OsSelect.isLinux()) {HCNetSDK.BYTE_ARRAY ptrByteArray1 = new HCNetSDK.BYTE_ARRAY(256);HCNetSDK.BYTE_ARRAY ptrByteArray2 = new HCNetSDK.BYTE_ARRAY(256);//这里是库的绝对路径,请根据实际情况修改,注意改路径必须有访问权限String strPath1 = linuxPath + "/libcrypto.so.1.1";String strPath2 = linuxPath + "/libssl.so.1.1";System.arraycopy(strPath1.getBytes(), 0, ptrByteArray1.byValue, 0, strPath1.length());ptrByteArray1.write();_DVR_SetSDKInitCfg(3, ptrByteArray1.getPointer());System.arraycopy(strPath2.getBytes(), 0, ptrByteArray2.byValue, 0, strPath2.length());ptrByteArray2.write();_DVR_SetSDKInitCfg(4, ptrByteArray2.getPointer());String strPathCom = linuxPath;_DVR_LOCAL_SDK_PATH struComPath = new _DVR_LOCAL_SDK_PATH();System.arraycopy(strPathCom.getBytes(), 0, struComPath.sPath, 0, strPathCom.length());struComPath.write();_DVR_SetSDKInitCfg(2, struComPath.getPointer());}//进行初始化boolean b = _DVR_Init();if (b) {backResult.setStatusCode(0);backResult.setStatusCodeMsg("初始化成功");} else {backResult.setStatusCode(_DVR_GetLastError());backResult.setStatusCodeMsg("初始化失败" + CommonUtil.getLastErrorMsg(_DVR_GetLastError()));}return backResult;}
7,设备登录
/*** 设备登录-登录时要注意设备是否已经登录** @param ipadress IP地址* @param user用户名* @param psw密码* @param port端口,默认8000* @return 登录成功返回用户登录语句柄, 否则返回操作错误码*/public static BackResult login(String ipadress, String user, String psw, short port) {//注册//设备登录信息_DVR_USER_LOGIN_INFO strLoginInfo = new _DVR_USER_LOGIN_INFO();//设备ip地址String sDeviceIp = ipadress;strLoginInfo.sDeviceAddress = new byte[_DVR_DEV_ADDRESS_MAX_LEN];System.arraycopy(sDeviceIp.getBytes(), 0, strLoginInfo.sDeviceAddress, 0, sDeviceIp.length());//设备用户名String sUsername = user;strLoginInfo.sUserName = new byte[_DVR_LOGIN_USERNAME_MAX_LEN];System.arraycopy(sUsername.getBytes(), 0, strLoginInfo.sUserName, 0, sUsername.length());//设备密码String sPassword = psw;strLoginInfo.sPassword = new byte[_DVR_LOGIN_PASSWD_MAX_LEN];System.arraycopy(sPassword.getBytes(), 0, strLoginInfo.sPassword, 0, sPassword.length());//sdk端口strLoginInfo.wPort = port;//是否异步登录:0- 否,1- 是strLoginInfo.bUseAsynLogin = false;strLoginInfo.write();//设备信息_DVR_DEVICEINFO_V40 strDeviceInfo = new _DVR_DEVICEINFO_V40();//lUserID登录该设备返回的语句柄--每台设备不一样BackResult backResult = new BackResult();int userId = _DVR_Login_V40(strLoginInfo, strDeviceInfo);if ((userId == -1) || (userId == 0xFFFFFFFF)) {backResult.setlUserId(userId);backResult.setStatusCode(_DVR_GetLastError());backResult.setStatusCodeMsg("登录失败:" + CommonUtil.getLastErrorMsg(_DVR_GetLastError()));return backResult;} else {strDeviceInfo.read();//编码类型iCharEncodeType = strDeviceInfo.byCharEncodeType;backResult.setStatusCode(0);backResult.setlUserId(userId);//初始的布防状态为-1,进行告警布防后获取布防状态backResult.setlAlarmHandle(-1);backResult.setStatusCodeMsg("登录成功");return backResult;}}