290 lines
8.7 KiB
Go
290 lines
8.7 KiB
Go
package iot
|
||
|
||
import (
|
||
"encoding/json"
|
||
"fmt"
|
||
|
||
"myschools.me/suguo/hikvision/iot/model"
|
||
)
|
||
|
||
// 远程 采集规则配置
|
||
func CaptureRemoteRuleSet(deviceSerial string, cardNoAdaptive bool, cardNoBytesLen, cardTimeout int) (*model.Hikvision, error) {
|
||
req := &struct {
|
||
DeviceSerial string `json:"deviceSerial"`
|
||
CardRule model.CaptureRemoteRule `json:"cardRule"`
|
||
}{
|
||
DeviceSerial: deviceSerial,
|
||
CardRule: model.CaptureRemoteRule{
|
||
CardNoAdaptive: cardNoAdaptive,
|
||
CardNoBytesLen: cardNoBytesLen,
|
||
CardTimeout: cardTimeout,
|
||
},
|
||
}
|
||
|
||
resp, err := hikvisionRequest("POST", "/api/v1/open/collectors/remote/rules/create", req)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
var result = &model.Hikvision{}
|
||
if err := json.Unmarshal(resp, &result); err != nil {
|
||
return nil, err
|
||
}
|
||
return result, nil
|
||
}
|
||
|
||
// 远程 获取采集规则配置
|
||
func CaptureRemoteRuleGet(deviceSerial string) (*model.CaptureRemoteRuleGet, error) {
|
||
|
||
resp, err := hikvisionRequest("GET", "/api/v1/open/collectors/remote/rules/get?deviceSerial="+deviceSerial, nil)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
var result = &model.CaptureRemoteRuleGet{}
|
||
if err := json.Unmarshal(resp, &result); err != nil {
|
||
return nil, err
|
||
}
|
||
return result, nil
|
||
}
|
||
|
||
// 远程 采集并获取身份证信息
|
||
func CaptureRemoteIDCardGet(deviceSerial string) (*model.CaptureRemoteIDCardGet, error) {
|
||
req := &struct {
|
||
DeviceSerial string `json:"deviceSerial"`
|
||
}{
|
||
DeviceSerial: deviceSerial,
|
||
}
|
||
resp, err := hikvisionRequest("POST", "/api/v1/open/collectors/remote/identities/actions/get", req)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
var result = &model.CaptureRemoteIDCardGet{}
|
||
if err := json.Unmarshal(resp, &result); err != nil {
|
||
return nil, err
|
||
}
|
||
return result, nil
|
||
}
|
||
|
||
// 远程 采集并获取卡信息,默认5秒左右超时,如果配置了采集规则,以规则配置接口中cardTimeout的值为准。
|
||
func CaptureRemoteCardGet(deviceSerial string) (*model.CaptureRemoteCardGet, error) {
|
||
|
||
req := &struct {
|
||
DeviceSerial string `json:"deviceSerial"`
|
||
}{
|
||
DeviceSerial: deviceSerial,
|
||
}
|
||
resp, err := hikvisionRequest("POST", "/api/v1/open/collectors/remote/cards/actions/get", req)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
var result = &model.CaptureRemoteCardGet{}
|
||
if err := json.Unmarshal(resp, &result); err != nil {
|
||
return nil, err
|
||
}
|
||
return result, nil
|
||
}
|
||
|
||
// 远程 采集并获取指纹信息,手指需要进行3次感应,最好在10秒内完成采集。
|
||
func CaptureRemoteFingerPrintGet(deviceSerial string, fingerprintNo int) (*model.CaptureRemoteFingerPrintGet, error) {
|
||
|
||
req := &struct {
|
||
DeviceSerial string `json:"deviceSerial"`
|
||
FingerprintNo int `json:"fingerprintNo"` //指纹编号,取值范围:[1~10]
|
||
}{
|
||
DeviceSerial: deviceSerial,
|
||
FingerprintNo: fingerprintNo,
|
||
}
|
||
resp, err := hikvisionRequest("POST", "/api/v1/open/collectors/remote/fingerprints/actions/get", req)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
var result = &model.CaptureRemoteFingerPrintGet{}
|
||
if err := json.Unmarshal(resp, &result); err != nil {
|
||
return nil, err
|
||
}
|
||
return result, nil
|
||
}
|
||
|
||
// 远程 采集并获取人脸信息
|
||
func CaptureRemoteFaceGet(deviceSerial string, infrared bool) (*model.CaptureRemoteFaceGet, error) {
|
||
|
||
req := &struct {
|
||
DeviceSerial string `json:"deviceSerial"`
|
||
Infrared bool `json:"infrared"`
|
||
}{
|
||
DeviceSerial: deviceSerial,
|
||
Infrared: infrared,
|
||
}
|
||
resp, err := hikvisionRequest("POST", "/api/v1/open/collectors/remote/faces/actions/get", req)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
var result = &model.CaptureRemoteFaceGet{}
|
||
if err := json.Unmarshal(resp, &result); err != nil {
|
||
return nil, err
|
||
}
|
||
return result, nil
|
||
}
|
||
|
||
// 远程 如果采集人脸信息接口采集进度不为100,且未返回人脸照片URL时,调用该接口查询采集进度以及获取人脸URL。
|
||
func CaptureRemoteFaceProcessGet(deviceSerial string) (*model.CaptureRemoteFaceGet, error) {
|
||
|
||
resp, err := hikvisionRequest("GET", fmt.Sprintf("%s?deviceSerial=%s", "/api/v1/open/collectors/remote/faces/actions/getProgress", deviceSerial), nil)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
var result = &model.CaptureRemoteFaceGet{}
|
||
if err := json.Unmarshal(resp, &result); err != nil {
|
||
return nil, err
|
||
}
|
||
return result, nil
|
||
}
|
||
|
||
// 本地 规则配置
|
||
func CaptureLocalRuleSet(deviceSerial string, reqAdminRights, cardNoAdaptive bool, rules []model.CaptureLocalRule) (*model.Hikvision, error) {
|
||
req := &struct {
|
||
DeviceSerial string `json:"deviceSerial"`
|
||
ReqAdminRights bool `json:"reqAdminRights"` //是否需要管理员权限
|
||
CardNoAdaptive bool `json:"cardNoAdaptive"` //卡号长度自适应
|
||
Rules []model.CaptureLocalRule `json:"rules"`
|
||
}{
|
||
DeviceSerial: deviceSerial,
|
||
ReqAdminRights: reqAdminRights,
|
||
CardNoAdaptive: cardNoAdaptive,
|
||
Rules: rules,
|
||
}
|
||
|
||
resp, err := hikvisionRequest("POST", "/api/v1/open/collectors/local/rules"+"/create", req)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
var result = &model.Hikvision{}
|
||
if err := json.Unmarshal(resp, &result); err != nil {
|
||
return nil, err
|
||
}
|
||
return result, nil
|
||
}
|
||
|
||
// 本地 获取规则配置
|
||
func CaptureLocalRuleGet(deviceSerial string) (*model.CaptureLocalRuleGet, error) {
|
||
|
||
resp, err := hikvisionRequest("GET", "/api/v1/open/collectors/local/rules"+"/get?deviceSerial="+deviceSerial, nil)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
var result = &model.CaptureLocalRuleGet{}
|
||
if err := json.Unmarshal(resp, &result); err != nil {
|
||
return nil, err
|
||
}
|
||
return result, nil
|
||
}
|
||
|
||
// 本地 录入人员信息
|
||
func CaptureLocalPeopleCreate(deviceSerial, employeeNos, name, idCardNo string, cardNos []string) (*model.Hikvision, error) {
|
||
req := &struct {
|
||
DeviceSerial string `json:"deviceSerial"`
|
||
EmployeeNo string `json:"employeeNo"`
|
||
Name string `json:"name"`
|
||
IdcardNo string `json:"idcardNo"`
|
||
CardNos []string `json:"cardNos"`
|
||
}{
|
||
DeviceSerial: deviceSerial,
|
||
EmployeeNo: employeeNos,
|
||
Name: name,
|
||
IdcardNo: idCardNo,
|
||
CardNos: cardNos,
|
||
}
|
||
|
||
resp, err := hikvisionRequest("POST", "/api/v1/open/collectors/local/people/create", req)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
var result = &model.Hikvision{}
|
||
if err := json.Unmarshal(resp, &result); err != nil {
|
||
return nil, err
|
||
}
|
||
return result, nil
|
||
}
|
||
|
||
// 本地 查询采集数据
|
||
func CaptureLocalSearch(deviceSerial, searchId string, searchResultPosition, maxResults int, searchType string, employeeNos []string) (*model.CaptureLocalSearch, error) {
|
||
req := &struct {
|
||
DeviceSerial string `json:"deviceSerial"`
|
||
SearchId string `json:"searchId"`
|
||
SearchResultPosition int `json:"searchResultPosition"`
|
||
MaxResults int `json:"maxResults"`
|
||
SearchType string `json:"searchType"`
|
||
EmployeeNos []string `json:"employeeNos"`
|
||
}{
|
||
DeviceSerial: deviceSerial,
|
||
SearchId: searchId,
|
||
SearchResultPosition: searchResultPosition,
|
||
MaxResults: maxResults,
|
||
SearchType: searchType,
|
||
EmployeeNos: employeeNos,
|
||
}
|
||
|
||
resp, err := hikvisionRequest("POST", "/api/v1/open/collectors/local/actions/search", req)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
var result = &model.CaptureLocalSearch{}
|
||
if err := json.Unmarshal(resp, &result); err != nil {
|
||
return nil, err
|
||
}
|
||
return result, nil
|
||
}
|
||
|
||
// 本地 获取采集状态信息
|
||
func CaptureLocalStatusGet(deviceSerial string) (*model.CaptureLocalStatusGet, error) {
|
||
|
||
resp, err := hikvisionRequest("GET", "/api/v1/open/collectors/local/actions/getStatus"+"?deviceSerial="+deviceSerial, nil)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
var result = &model.CaptureLocalStatusGet{}
|
||
if err := json.Unmarshal(resp, &result); err != nil {
|
||
return nil, err
|
||
}
|
||
return result, nil
|
||
}
|
||
|
||
// 本地 删除全部采集数据
|
||
func CaptureLocalDeleteAll(deviceSerial string) (*model.Hikvision, error) {
|
||
req := &struct {
|
||
DeviceSerial string `json:"deviceSerial"`
|
||
}{
|
||
DeviceSerial: deviceSerial,
|
||
}
|
||
|
||
resp, err := hikvisionRequest("POST", "/api/v1/open/collectors/local/actions/deleteAll", req)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
var result = &model.Hikvision{}
|
||
if err := json.Unmarshal(resp, &result); err != nil {
|
||
return nil, err
|
||
}
|
||
return result, nil
|
||
}
|
||
|
||
// 本地 根据人员编号删除采集数据
|
||
func CaptureLocalDeleteByEmployeeNos(deviceSerial string, employeeNos []string) (*model.Hikvision, error) {
|
||
req := &struct {
|
||
DeviceSerial string `json:"deviceSerial"`
|
||
EmployeeNos []string `json:"employeeNos"`
|
||
}{
|
||
DeviceSerial: deviceSerial,
|
||
EmployeeNos: employeeNos,
|
||
}
|
||
|
||
resp, err := hikvisionRequest("POST", "/api/v1/open/collectors/local/actions/deleteByEmployeeNos", req)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
var result = &model.Hikvision{}
|
||
if err := json.Unmarshal(resp, &result); err != nil {
|
||
return nil, err
|
||
}
|
||
return result, nil
|
||
}
|