首页 > 其他分享 >获取门禁记录方式-主动获取

获取门禁记录方式-主动获取

时间:2023-05-26 17:35:43浏览次数:41  
标签:case return 记录 指纹 认证 获取 NET 门禁 DVR

主动获取

类似于获取门禁记录,通过代入的查询条件获取范围内的记录信息,使用该方式时需要注意时间范围不要重复或者获取数据后有查重操作,否则会出现重复的情况。

流程中的1,2,6,7的代码请参见《获取门禁记录方式-公用方法》

流程
  1. NET_DVR_Init(初始化)

  2. NET_DVR_Login_V40(登录获得UserId)

  3. NET_DVR_StartRemoteConfig(获取查记录的句柄)

    1. 引用方法

      int NET_DVR_StartRemoteConfig(int lUserID, int dwCommand, IntPtr lpInBuffer, Int32 dwInBufferLen, RemoteConfigCallback cbStateCallback, IntPtr pUserData)

    2. 参数说明

      参数 说明
      lUserID 登录句柄
      dwCommand 命令,该例子中为NET_DVR_GET_ACS_EVENT(2514)
      lpInBuffer NET_DVR_ACS_EVENT_COND类的实例,转换为IntPtr
      dwInBufferLen NET_DVR_ACS_EVENT_COND类的实例长度
      cbStateCallback null
      pUserData IntPtr.Zero
      返回值 该次查询的句柄,下一步需要使用
    3. 代码举例

      //获得查询条件
      CHCNetSDK.NET_DVR_ACS_EVENT_COND cond = GetAcsEventCond(searchCond, isSearchAll);
      uint dwSize = cond.dwSize;
      // 声明cond实例大小的IntPtr
      IntPtr ptrCond = Marshal.AllocHGlobal((int)dwSize);
      // 将cond转换为IntPtr
      Marshal.StructureToPtr(cond, ptrCond, false);
      // 实例
      int recordCfgHandle = CHCNetSDK.NET_DVR_StartRemoteConfig(lUserID, CHCNetSDK.NET_DVR_GET_ACS_EVENT, ptrCond, (int)dwSize, null, IntPtr.Zero);
      // 如果userCfgHandle为-1时,则不能查询,原因可能是没有释放之前的查询句柄,可通过GetLastError来判断
      

      GetAcsEventCond方法代码

      /// <summary>
      /// 根据条件获得NET_DVR_ACS_EVENT_COND实例
      /// </summary>
      /// <param name="searchCond">
      /// key             说明
      /// beginTime       查询记录的起时间
      /// endTime         查询记录的止时间
      /// </param>
      /// <param name="isSearchAll">是否查询全部</param>
      /// <returns></returns>
      private CHCNetSDK.NET_DVR_ACS_EVENT_COND GetAcsEventCond(Dictionary<string, string> searchCond, bool isSearchAll)
      {
          CHCNetSDK.NET_DVR_ACS_EVENT_COND cond = new CHCNetSDK.NET_DVR_ACS_EVENT_COND();
          cond.Init();
          cond.dwSize = (uint)Marshal.SizeOf(cond);
          //报警主类型
          cond.dwMajor = 5;
          //报警次类型,0为全部
          cond.dwMinor = 0;
          //是否带图片,0-不带图片,1-带图片
          cond.byPicEnable = 0;
          //归纳事件类型,全部都要
          cond.wInductiveEventType = 65535;
          // 如果是全部信息,则不需要设置起始时间
          if (!isSearchAll)
          {
              if (null != searchCond && searchCond.ContainsKey("beginTime"))
              {
                  // 如果有beginTime,则获取
                  cond.struStartTime = CHCNetSDK.GetDvrStruTIme(searchCond["beginTime"]);
              }
              else
              {
                  // 如果没有,则默认为当前的凌晨开始
                  cond.struStartTime = CHCNetSDK.GetDvrStruTIme(String.Format("%s 00:00:00", DateTime.Now.ToString("yyyy-MM-dd")));
              }
              if (null != searchCond && searchCond.ContainsKey("endTime"))
              {
                  // 同上
                  cond.struEndTime = CHCNetSDK.GetDvrStruTIme(searchCond["endTime"]);
              }
              else
              {
                  // 同上
                  cond.struEndTime = CHCNetSDK.GetDvrStruTIme(String.Format("%s", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
              }
          }
          return cond;
      }
      

      GetDvrStruTIme方法

      /// <summary>
      /// 根据时间获得NET_DVR_TIME类型
      /// </summary>
      /// <param name="time">yyyy-MM-dd HH:mm:ss形式的字符串</param>
      /// <returns>NET_DVR_TIME</returns>
      public static NET_DVR_TIME GetDvrStruTIme(String time) {
          DateTime dateTime = System.DateTime.Now;
          if (!String.IsNullOrEmpty(time)) {
              try
              {
                  dateTime = Convert.ToDateTime(time);
              }
              catch (Exception ex) { }
          }
          NET_DVR_TIME condTime = new NET_DVR_TIME();
          condTime.dwYear = dateTime.Year;
          condTime.dwMonth = dateTime.Month;
          condTime.dwDay = dateTime.Day;
          condTime.dwHour = dateTime.Hour;
          condTime.dwMinute = dateTime.Minute;
          condTime.dwSecond = dateTime.Second;
          return condTime;
      }
      
  4. NET_DVR_GetNextRemoteConfig(一条一条获取)

    注意:代码不变的情况下,有时会返回1000(成功),有时会返回1002,错误码为19(设备返回数据异常);原因可能是在调试的时候,时长过长导致的。

    1. 引用方法

      int NET_DVR_GetNextRemoteConfig(int lHandle, ref CHCNetSDK.NET_DVR_ACS_EVENT_CFG lpOutBuff, int dwOutBuffSize);

    2. 参数说明

      参数 说明
      lHandle 查询句柄(NET_DVR_StartRemoteConfig返回值)
      lpOutBuff CUserInfoSearchCondCfg类的实例,检索条件
      dwOutBuffSize CUserInfoSearchCondCfg类的实例长度
      返回值 NET_SDK_GET_NEXT_STATUS_SUCCESS成功获取数据
    3. 代码举例

      // 存储门禁记录的list
      List<AcessLogEntity> acessLogEntities = new List<AcessLogEntity>();
      // 状态表示
      int dwStatus = 0;
      // 循环使用
      Boolean flag = true;
      // 门禁记录的类
      CHCNetSDK.NET_DVR_ACS_EVENT_CFG struCFG = new CHCNetSDK.NET_DVR_ACS_EVENT_CFG();
      struCFG.dwSize = (uint)Marshal.SizeOf(struCFG);
      int dwOutBuffSize = (int)struCFG.dwSize;
      // 门禁类里面的byte数组初始化
      struCFG.init();
      while (flag)
      {
          // 调用下一条下一条的方法
          dwStatus = CHCNetSDK.NET_DVR_GetNextRemoteConfig(recordCfgHandle, ref struCFG, dwOutBuffSize);
          switch (dwStatus)
          {
              case CHCNetSDK.NET_SDK_GET_NEXT_STATUS_SUCCESS://成功读取到数据,处理完本次数据后需调用next
                  // 获得门禁记录
                  // 注:personDic为获取到人员列表的编号对应姓名,因为门禁记录中貌似没有人员名称。personDic的获取不在本文中体现,可参考人员列表获取的相关文章。
                  AcessLogEntity acessLog = GetAccessLog(personDic, ref struCFG);
                  // 如果有
                  if (null != acessLog)
                  {
                      // 保存
                      acessLogEntities.Add(acessLog);
                  }
                  break;
              case CHCNetSDK.NET_SDK_GET_NEXT_STATUS_NEED_WAIT:
                  Thread.Sleep(200);
                  break;
              case CHCNetSDK.NET_SDK_GET_NEXT_STATUS_FAILED:
              case CHCNetSDK.NET_SDK_GET_NEXT_STATUS_FINISH:
              default:
                  CHCNetSDK.NET_DVR_StopRemoteConfig(recordCfgHandle);
                  flag = false;
                  break;
          }
      }
      

      GetAccessLog方法

      GetAccessLog的personDic参数为获取到人员列表的编号对应姓名,因为门禁记录中貌似没有人员名称。

      personDic的获取不在本文中体现,可参考人员列表获取的相关文章。

      /// <summary>
      /// 将NET_DVR_ACS_EVENT_CFG转换为AcessLogEntity
      /// </summary>
      /// <param name="personDic">人员的编号和姓名对应的字典</param>
      /// <param name="eventCfg">门禁记录</param>
      /// <returns></returns>
      private AcessLogEntity GetAccessLog(Dictionary<string, string> personDic, ref CHCNetSDK.NET_DVR_ACS_EVENT_CFG eventCfg)
      {
          AcessLogEntity acessLog = new AcessLogEntity();
          // 是什么记录,可通过对case的增减来选择性的获取记录
          string minorType = AcessLogEntity.GetMinorType(eventCfg.dwMinor);
          // 如果没有则返回null
          if (minorType.Length < 1)
          {
              return null;
          }
          // 门禁的类型
          acessLog.Verify = minorType;
          // 人员唯一编号,通过浏览器登录门禁,人员管理中现实的编号。
          acessLog.Pin = Encoding.ASCII.GetString(eventCfg.struAcsEventInfo.byEmployeeNo).Replace("\0", "");
          // 没有则跳过
          if (personDic.ContainsKey(acessLog.Pin))
          {
              acessLog.Name = personDic[acessLog.Pin];
          }
          // 卡号
          acessLog.Cardno = Encoding.ASCII.GetString(eventCfg.struAcsEventInfo.byCardNo);
          // 门禁产生的时间
          acessLog.AccessTime = String.Format("{0}-{1:D2}-{2:D2} {3:D2}:{4:D2}:{5:D2}", eventCfg.struTime.dwYear, eventCfg.struTime.dwMonth, eventCfg.struTime.dwDay, eventCfg.struTime.dwHour, eventCfg.struTime.dwMinute, eventCfg.struTime.dwSecond);
          return acessLog;
      }
      

      AcessLogEntity.GetMinorType方法

      可直接使用,如果想用“0x03 刷卡加密码认证通过”,只需要打开注释即可

      public static string GetMinorType(uint seek) {
          switch (seek)
          {
              case 0x01: return "合法卡认证通过";
              //case 0x02: return "刷卡加密码认证通过";
              //case 0x03: return "刷卡加密码认证失败";
              //case 0x04: return "数卡加密码认证超时";
              //case 0x05: return "刷卡加密码超次";
              //case 0x06: return "未分配权限";
              //case 0x07: return "无效时段";
              //case 0x08: return "卡号过期";
              //case 0x09: return "无此卡号";
              //case 0x0a: return "反潜回认证失败";
              //case 0x0b: return "互锁门未关闭";
              //case 0x0c: return "卡不属于多重认证群组";
              //case 0x0d: return "卡不在多重认证时间段内";
              //case 0x0e: return "多重认证模式超级权限认证失败";
              //case 0x0f: return "多重认证模式远程认证失败";
              case 0x10: return "多重认证成功";
              //case 0x11: return "首卡开门开始";
              //case 0x12: return "首卡开门结束";
              //case 0x13: return "常开状态开始";
              //case 0x14: return "常开状态结束";
              //case 0x15: return "门锁打开";
              //case 0x16: return "门锁关闭";
              case 0x17: return "开门按钮打开";
              //case 0x18: return "开门按钮放开";
              //case 0x19: return "正常开门(门磁)";
              //case 0x1a: return "正常关门(门磁)";
              //case 0x1b: return "门异常打开(门磁)";
              //case 0x1c: return "门打开超时(门磁)";
              //case 0x1d: return "报警输出打开";
              //case 0x1e: return "报警输出关闭";
              //case 0x1f: return "常关状态开始";
              //case 0x20: return "常关状态结束";
              //case 0x21: return "多重多重认证需要远程开门";
              //case 0x22: return "多重认证超级密码认证成功事件";
              //case 0x23: return "多重认证重复认证事件";
              //case 0x24: return "多重认证重复认证事件";
              //case 0x25: return "门铃响";
              case 0x26: return "指纹比对通过";
              //case 0x27: return "指纹比对失败";
              case 0x28: return "刷卡加指纹认证通过";
              //case 0x29: return "刷卡加指纹认证失败";
              //case 0x2a: return "刷卡加指纹认证超时";
              case 0x2b: return "刷卡加指纹加密码认证通过";
              //case 0x2c: return "刷卡加指纹加密码认证失败";
              //case 0x2d: return "刷卡加指纹加密码认证超时";
              case 0x2e: return "指纹加密码认证通过";
              //case 0x2f: return "指纹加密码认证失败";
              //case 0x30: return "指纹加密码认证超时";
              //case 0x31: return "指纹不存在";
              //case 0x32: return "刷卡平台认证";
              //case 0x33: return "呼叫中心事件";
              //case 0x34: return "消防继电器导通触发门常开";
              //case 0x35: return "消防继电器恢复门恢复正常";
              case 0x36: return "人脸加指纹认证通过";
              //case 0x37: return "人脸加指纹认证失败";
              //case 0x38: return "人脸加指纹认证超时";
              case 0x39: return "人脸加密码认证通过";
              //case 0x3a: return "人脸加密码认证失败";
              //case 0x3b: return "人脸加密码认证超时";
              case 0x3c: return "人脸加刷卡认证通过";
              //case 0x3d: return "人脸加刷卡认证失败";
              //case 0x3e: return "人脸加刷卡认证超时";
              case 0x3f: return "人脸加密码加指纹认证通过";
              //case 0x40: return "人脸加密码加指纹认证失败";
              //case 0x41: return "人脸加密码加指纹认证超时";
              case 0x42: return "人脸加刷卡加指纹认证通过";
              //case 0x43: return "人脸加刷卡加指纹认证失败";
              //case 0x44: return "人脸加刷卡加指纹认证超时";
              case 0x45: return "工号加指纹认证通过";
              //case 0x46: return "工号加指纹认证失败";
              //case 0x47: return "工号加指纹认证超时";
              case 0x48: return "工号加指纹加密码认证通过";
              //case 0x49: return "工号加指纹加密码认证失败";
              //case 0x4a: return "工号加指纹加密码认证超时";
              case 0x4b: return "人脸认证通过";
              //case 0x4c: return "人脸认证失败";
              case 0x4d: return "工号加人脸认证通过";
              //case 0x4e: return "工号加人脸认证失败";
              //case 0x4f: return "工号加人脸认证超时";
              //case 0x50: return "人脸识别失败";
              //case 0x51: return "首卡授权开始";
              //case 0x52: return "首卡授权结束";
              //case 0x53: return "门锁输入短路报警";
              //case 0x54: return "门锁输入断路报警";
              //case 0x55: return "门锁输入异常报警";
              //case 0x56: return "门磁输入短路报警";
              //case 0x57: return "门磁输入断路报警";
              //case 0x58: return "门磁输入异常报警";
              //case 0x59: return "开门按钮输入短路报警";
              //case 0x5a: return "开门按钮输入断路报警";
              //case 0x5b: return "开门按钮输入异常报警";
              //case 0x5c: return "门锁异常打开";
              //case 0x5d: return "门锁打开超时";
              //case 0x5e: return "首卡未授权开门失败";
              //case 0x5f: return "呼梯继电器断开";
              //case 0x60: return "呼梯继电器闭合";
              //case 0x61: return "自动按键继电器断开";
              //case 0x62: return "自动按键继电器闭合";
              //case 0x63: return "按键梯控继电器断开";
              //case 0x64: return "按键梯控继电器闭合";
              case 0x65: return "工号加密码认证通过";
              //case 0x66: return "工号加密码认证失败";
              //case 0x67: return "工号加密码认证超时";
              //case 0x68: return "真人检测失败";
              case 0x69: return "人证比对通过";
              //case 0x70: return "人证比对失败";
              //case 0x71: return "黑名单事件";
              //case 0x72: return "合法短信";
              //case 0x73: return "非法短信";
              //case 0x74: return "MAC侦测";
              //case 0x75: return "门状态常闭或休眠状态认证失败";
              //case 0x76: return "认证计划休眠模式认证失败";
              //case 0x77: return "卡加密校验失败";
              //case 0x78: return "反潜回服务器应答失败";
              //case 0x85: return "尾随通行";
              //case 0x86: return "反向闯入";
              //case 0x87: return "外力冲撞";
              //case 0x88: return "翻越";
              //case 0x89: return "通行超时";
              //case 0x8a: return "误闯报警";
              //case 0x8b: return "闸机自由通行时未认证通过";
              //case 0x8c: return "摆臂被阻挡";
              //case 0x8d: return "摆臂阻挡消除";
              //case 0x8e: return "设备升级本地人脸建模失败";
              //case 0x8f: return "逗留事件";
              //case 0x97: return "密码不匹配";
              //case 0x98: return "工号不存在";
              case 0x99: return "组合认证通过";
              //case 0x9a: return "组合认证超时";
              //case 0x9b: return "认证方式不匹配";
              default:
                  return "";
          }
      }
      

      AcessLogEntity类可根据自己的实际情况进行声明

  5. NET_DVR_StopRemoteConfig(释放该次查询句柄)

    1. 引用方法

      int NET_DVR_StartRemoteConfig(int lUserID, int dwCommand, IntPtr lpInBuffer, Int32 dwInBufferLen, RemoteConfigCallback cbStateCallback, IntPtr pUserData)

    2. 参数说明

      参数 说明
      lUserID 登录句柄
      dwCommand 命令,该例子中为NET_DVR_JSON_CONFIG(2550)
      lpInBuffer url转换的IntPtr
      dwInBufferLen url的长度
      cbStateCallback null
      pUserData IntPtr.Zero
      返回值 该次查询的句柄,下一步需要使用
    3. 代码举例

  6. NET_DVR_Logout(注销)

  7. NET_DVR_Cleanup(结束)

标签:case,return,记录,指纹,认证,获取,NET,门禁,DVR
From: https://www.cnblogs.com/wanghun315/p/17435343.html

相关文章

  • 门禁获取门禁记录-公用部分说明
    公用部分NET_DVR_Init(初始化)boolCHCNetSDK.NET_DVR_Init()初始化海康组件返回值:true:初始化成功false:失败,失败原因:海康SDK分32位和64位,项目中目标平台一定要与SDK一致(项目右键->属性->生成->目标平台)DllImport的HCNetSDK.dll路径不对,如果使用绝对路径也不对时,路径不要......
  • EasyDSS如何调用接口获取录像MP4文件合成状态?
    EasyDSS互联网视频云服务的视频直播/点播功能支持视频采集、编辑、上传、媒体资源管理、自动化转码处理、分发服务等,帮助用户快速搭建拥有极致观看体验、安全可靠的视频直播点播应用。有用户反馈在调用接口时,会出现合成中的字样,并不知道合成的录像MP4文件是否已经合成完毕。今天我......
  • Windows驱动开发学习记录-使用Inf安装过滤驱动时自动添加注册表相关内容
     做过滤驱动时一般需要在相关class驱动里添加过滤信息,即LowerFilters或者UpperFilters,比如disk类的注册表当前信息,如下图:一个常规的inf文件如下所示:;;USBFilter.inf;[Version]Signature="$WINDOWSNT$"Class=TOASTERClassGuid={B85B7C50-6A01-11d2-B841-00C04FAD517......
  • Shopee|Lazada电商平台api接口,接入获取商品评论|根据关键词取商品列表API说明示例
     Shopee和Lazada是东南亚地区广受欢迎的电商平台。它们的模式非常类似,都是以C2C(消费者到消费者)、B2C(企业到消费者)和O2O(线上到线下)为主要销售模式。用户可以在平台上购买商品或者将自己的商品出售给其他用户。这些平台提供了较高的使用便利性,比如支持多种支付方式、商品搜索......
  • Lazada平台如何获取信息并调用呢?
    LazadaisoneofthelargestonlinemarketplacesinSoutheastAsia.Itoffersawidevarietyofproductsacrosscategoriessuchaselectronics,fashion,homeandliving,andhealthandbeauty.OneofthekeyreasonsforitssuccessisitsAPIsorApplicat......
  • java连接TD数据库获取数据
    1.目录结构2.创建springboot的项目,添加pom依赖3.配置数据库连接池4.配置数据库映射实体5.配置dao层6.书写对应的xml格式的对应这里举例一个查询最新的一个数据7.Service层8.Controller层通过接口返回给前端9.初始化数据库10.通过接口获取lastone可以......
  • 算法学习记录(模拟枚举贪心题单):四舍五入(未AC)
    题目链接https://ac.nowcoder.com/acm/contest/20960/1004题目分析注意当第i位为9是,此时进位就是0,但是0<5,所以就不能再用i+1进行判断了。所以对于这种情况可以再添加一个其他变量。未AC代码//主要解决问题,因为使用i+1去判断是否要进位的//逢9进位后就会变成0,那么第i+1位......
  • FLEX实践—获取当前窗口大小
       在FLEX中获取当前窗口的长度与宽度使用下面的方法:   Application.application.width   Application.application.height    在设置弹出窗口的长与宽的时候可以根据比例来设置,而不用将其长与宽设置为固定值。这样做的好处是考虑到了IE窗口的大小,通过比例设置可......
  • 帆软学习随笔记录
    --模板>模板Web属性>填报页面设置-为该模板单独设置,添加加载结束事件(JS实现根据当前sheet隐藏参数面板)$(".fr-sheetbutton-container").click(function() //给切换sheet的按钮绑定点击事件 { vara=_g().selectedIndex; //获取当前sheet的编号(从0开始) if(a==1){ //如......
  • c#读写锁浅记录
    publicclassC{staticprivateReaderWriterLockSlimrwl=newReaderWriterLockSlim();publicstaticvoidMain(){Threadt_read1=newThread(newThreadStart(WriteSomething));t_read1.Start();Console.WriteLine("{0}C......