人员信息采集-本地采集方式

This commit is contained in:
wyh 2023-11-23 17:27:27 +08:00
parent 005a421d72
commit d749d3e0ce
3 changed files with 397 additions and 70 deletions

View File

@ -8,15 +8,24 @@ import (
) )
const ( const (
capture_rule = "/api/v1/open/collectors/remote/rules" capture_remote = "/api/v1/open/collectors/remote"
capture_idcard = "/api/v1/open/collectors/remote/identities/actions/get" capture_remote_rule = capture_remote + "/rules"
capture_card = "/api/v1/open/collectors/remote/cards/actions/get" capture_remote_idcard = capture_remote + "/identities/actions/get"
capture_fingerprint = "/api/v1/open/collectors/remote/fingerprints/actions/get" capture_remote_card = capture_remote + "/cards/actions/get"
capture_face = "/api/v1/open/collectors/remote/faces/actions/get" capture_remote_fingerprint = capture_remote + "/fingerprints/actions/get"
capture_face_process = "/api/v1/open/collectors/remote/faces/actions/getProgress" capture_remote_face = capture_remote + "/faces/actions/get"
capture_remote_faceprocess = capture_remote + "/faces/actions/getProgress"
capture_local = "/api/v1/open/collectors/local"
capture_local_rule = capture_local + "/rules"
capture_local_people = capture_local + "/people/create"
capture_local_search = capture_local + "/actions/search"
capture_local_status = capture_local + "/actions/getStatus"
capture_local_deleteall = capture_local + "/actions/deleteAll"
capture_local_deletebyemployeenos = capture_local + "/actions/deleteByEmployeeNos"
) )
// 采集规则配置 // 远程 采集规则配置
func CaptureRemoteRuleSet(deviceSerial string, cardNoAdaptive bool, cardNoBytesLen, cardTimeout int) (*model.Hikvision, error) { func CaptureRemoteRuleSet(deviceSerial string, cardNoAdaptive bool, cardNoBytesLen, cardTimeout int) (*model.Hikvision, error) {
req := &struct { req := &struct {
DeviceSerial string `json:"deviceSerial"` DeviceSerial string `json:"deviceSerial"`
@ -30,7 +39,7 @@ func CaptureRemoteRuleSet(deviceSerial string, cardNoAdaptive bool, cardNoBytesL
}, },
} }
resp, err := hikvisionRequest("POST", capture_rule+"/create", req) resp, err := hikvisionRequest("POST", capture_remote_rule+"/create", req)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -41,10 +50,10 @@ func CaptureRemoteRuleSet(deviceSerial string, cardNoAdaptive bool, cardNoBytesL
return result, nil return result, nil
} }
// 获取采集规则配置 // 远程 获取采集规则配置
func CaptureRemoteRuleGet(deviceSerial string) (*model.CaptureRemoteRuleGet, error) { func CaptureRemoteRuleGet(deviceSerial string) (*model.CaptureRemoteRuleGet, error) {
resp, err := hikvisionRequest("GET", capture_rule+"/get?deviceSerial="+deviceSerial, nil) resp, err := hikvisionRequest("GET", capture_remote_rule+"/get?deviceSerial="+deviceSerial, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -55,14 +64,14 @@ func CaptureRemoteRuleGet(deviceSerial string) (*model.CaptureRemoteRuleGet, err
return result, nil return result, nil
} }
// 采集并获取身份证信息 // 远程 采集并获取身份证信息
func CaptureRemoteIDCardGet(deviceSerial string) (*model.CaptureRemoteIDCardGet, error) { func CaptureRemoteIDCardGet(deviceSerial string) (*model.CaptureRemoteIDCardGet, error) {
req := &struct { req := &struct {
DeviceSerial string `json:"deviceSerial"` DeviceSerial string `json:"deviceSerial"`
}{ }{
DeviceSerial: deviceSerial, DeviceSerial: deviceSerial,
} }
resp, err := hikvisionRequest("POST", capture_idcard, req) resp, err := hikvisionRequest("POST", capture_remote_idcard, req)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -73,7 +82,7 @@ func CaptureRemoteIDCardGet(deviceSerial string) (*model.CaptureRemoteIDCardGet,
return result, nil return result, nil
} }
// 采集并获取卡信息默认5秒左右超时如果配置了采集规则以规则配置接口中cardTimeout的值为准。 // 远程 采集并获取卡信息默认5秒左右超时如果配置了采集规则以规则配置接口中cardTimeout的值为准。
func CaptureRemoteCardGet(deviceSerial string) (*model.CaptureRemoteCardGet, error) { func CaptureRemoteCardGet(deviceSerial string) (*model.CaptureRemoteCardGet, error) {
req := &struct { req := &struct {
@ -81,7 +90,7 @@ func CaptureRemoteCardGet(deviceSerial string) (*model.CaptureRemoteCardGet, err
}{ }{
DeviceSerial: deviceSerial, DeviceSerial: deviceSerial,
} }
resp, err := hikvisionRequest("POST", capture_card, req) resp, err := hikvisionRequest("POST", capture_remote_card, req)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -92,7 +101,7 @@ func CaptureRemoteCardGet(deviceSerial string) (*model.CaptureRemoteCardGet, err
return result, nil return result, nil
} }
// 采集并获取指纹信息手指需要进行3次感应最好在10秒内完成采集。 // 远程 采集并获取指纹信息手指需要进行3次感应最好在10秒内完成采集。
func CaptureRemoteFingerPrintGet(deviceSerial string, fingerprintNo int) (*model.CaptureRemoteFingerPrintGet, error) { func CaptureRemoteFingerPrintGet(deviceSerial string, fingerprintNo int) (*model.CaptureRemoteFingerPrintGet, error) {
req := &struct { req := &struct {
@ -102,7 +111,7 @@ func CaptureRemoteFingerPrintGet(deviceSerial string, fingerprintNo int) (*model
DeviceSerial: deviceSerial, DeviceSerial: deviceSerial,
FingerprintNo: fingerprintNo, FingerprintNo: fingerprintNo,
} }
resp, err := hikvisionRequest("POST", capture_fingerprint, req) resp, err := hikvisionRequest("POST", capture_remote_fingerprint, req)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -113,7 +122,7 @@ func CaptureRemoteFingerPrintGet(deviceSerial string, fingerprintNo int) (*model
return result, nil return result, nil
} }
// 采集并获取人脸信息 // 远程 采集并获取人脸信息
func CaptureRemoteFaceGet(deviceSerial string, infrared bool) (*model.CaptureRemoteFaceGet, error) { func CaptureRemoteFaceGet(deviceSerial string, infrared bool) (*model.CaptureRemoteFaceGet, error) {
req := &struct { req := &struct {
@ -123,7 +132,7 @@ func CaptureRemoteFaceGet(deviceSerial string, infrared bool) (*model.CaptureRem
DeviceSerial: deviceSerial, DeviceSerial: deviceSerial,
Infrared: infrared, Infrared: infrared,
} }
resp, err := hikvisionRequest("POST", capture_face, req) resp, err := hikvisionRequest("POST", capture_remote_face, req)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -134,10 +143,10 @@ func CaptureRemoteFaceGet(deviceSerial string, infrared bool) (*model.CaptureRem
return result, nil return result, nil
} }
// 如果采集人脸信息接口采集进度不为100且未返回人脸照片URL时调用该接口查询采集进度以及获取人脸URL。 // 远程 如果采集人脸信息接口采集进度不为100且未返回人脸照片URL时调用该接口查询采集进度以及获取人脸URL。
func CaptureRemoteFaceProcessGet(deviceSerial string) (*model.CaptureRemoteFaceGet, error) { func CaptureRemoteFaceProcessGet(deviceSerial string) (*model.CaptureRemoteFaceGet, error) {
resp, err := hikvisionRequest("GET", fmt.Sprintf("%s?deviceSerial=%s", capture_face_process, deviceSerial), nil) resp, err := hikvisionRequest("GET", fmt.Sprintf("%s?deviceSerial=%s", capture_remote_faceprocess, deviceSerial), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -147,3 +156,152 @@ func CaptureRemoteFaceProcessGet(deviceSerial string) (*model.CaptureRemoteFaceG
} }
return result, nil 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", capture_local_rule+"/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", capture_local_rule+"/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", capture_local_people, 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", capture_local_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", capture_local_status+"?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", capture_local_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", capture_local_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
}

View File

@ -61,3 +61,95 @@ type CaptureRemoteFaceGet struct {
InfraredUrl string `json:"infraredUrl"` InfraredUrl string `json:"infraredUrl"`
} `json:"data"` } `json:"data"`
} }
type CaptureLocalRuleGet struct {
Hikvision
Data struct {
Progress int `json:"progress"`
FaceUrl string `json:"faceUrl"`
InfraredUrl struct {
ReqAdminRights bool `json:"reqAdminRights"`
CardNoAdaptive bool `json:"cardNoAdaptive"`
Rules []struct {
DataType string `json:"dataType"`
Enable bool `json:"enable"`
UniqueCheck bool `json:"uniqueCheck"`
Length int `json:"length"`
} `json:"rules"`
} `json:"infraredUrl"`
} `json:"data"`
}
type CaptureLocalSearch struct {
Hikvision
Data struct {
SearchId string `json:"searchId"`
NumOfMatches int `json:"numOfMatches"`
TotalMatches int `json:"totalMatches"`
Records []struct {
LastCaptureNo int `json:"lastCaptureNo"`
CaptureNo int `json:"captureNo"`
Name string `json:"name"`
EmployeeNo string `json:"employeeNo"`
IdcardNo string `json:"idcardNo"`
RiskDataMark bool `json:"riskDataMark"`
DataType string `json:"dataType"`
FaceUrl string `json:"faceUrl"`
Cards []struct {
CardNo string `json:"cardNo"`
CardType string `json:"cardType"`
} `json:"cards"`
Fingerprints []struct {
FingerprintNo int `json:"fingerprintNo"`
FingerprintData string `json:"fingerprintData"`
} `json:"fingerprints"`
IdentityInfo struct {
ChnName string `json:"chnName"`
EnName string `json:"enName"`
Gender string `json:"gender"`
Birth string `json:"birth"`
Addr string `json:"addr"`
IdcardNo string `json:"idcardNo"`
IssuingAuthority string `json:"issuingAuthority"`
StartDate string `json:"startDate"`
EndDate string `json:"endDate"`
Nation int `json:"nation"`
PassNo string `json:"passNo"`
IssueNumber string `json:"issueNumber"`
CertificateType string `json:"certificateType"`
PermanentResidenceCardNo string `json:"permanentResidenceCardNo"`
NationalityOrAreaCode string `json:"nationalityOrAreaCode"`
Version string `json:"version"`
ReceivingAuthorityCode string `json:"receivingAuthorityCode"`
FaceData string `json:"faceData"`
Fingerprints []string `json:"fingerprints"`
} `json:"identityInfo"`
} `json:"records"`
} `json:"data"`
}
type CaptureLocalStatusGet struct {
Hikvision
Data struct {
ReqCaptureNum int `json:"reqCaptureNum"`
CompletelyCaptureNum int `json:"completelyCaptureNum"`
PartiallyCaptureNum int `json:"partiallyCaptureNum"`
ReqFaceNum int `json:"reqFaceNum"`
FaceNum int `json:"faceNum"`
ReqFingerprintNum int `json:"reqFingerprintNum"`
FingerprintNum int `json:"fingerprintNum"`
ReqCardNum int `json:"reqCardNum"`
CardNum int `json:"cardNum"`
ReqIdcardNum int `json:"reqIdcardNum"`
IdcardNum int `json:"idcardNum"`
} `json:"data"`
}
type CaptureLocalRule struct {
DataType string `json:"dataType"`
Enable bool `json:"enable"`
UniqueCheck bool `json:"uniqueCheck"` //类型为name使用
FingerPrintNos []int `json:"fingerprintNos"` //类型为fingprint使用
Number int `json:"number"` //类型为fingprint,card使用
Length int `json:"length"`
}

View File

@ -1,61 +1,11 @@
package iot package iot
import ( import (
"fmt"
"log"
"testing" "testing"
) )
func TestOauth(t *testing.T) { func TestOauth(t *testing.T) {
deviceserial := "AF8534579"
// r0, err := CaptureRemoteRuleSet(deviceserial, true, 0, 50000)
// if err != nil {
// log.Fatal(err)
// return
// }
// fmt.Println(r0)
// r1, err := CaptureRemoteRuleGet(deviceserial)
// if err != nil {
// log.Fatal(err)
// return
// }
// fmt.Println(r1)
// r2, err := CaptureRemoteIDCardGet(deviceserial)
// if err != nil {
// log.Fatal(err)
// return
// }
// fmt.Println(r2)
// r3, err := CaptureRemoteCardGet(deviceserial)
// if err != nil {
// log.Fatal(err)
// return
// }
// fmt.Println(r3)
// r4, err := CaptureRemoteFingerPrintGet(deviceserial, 1)
// if err != nil {
// log.Fatal(err)
// return
// }
// fmt.Println(r4)
r5, err := CaptureRemoteFaceGet(deviceserial, false)
if err != nil {
log.Fatal(err)
return
}
fmt.Println(r5)
r6, err := CaptureRemoteFaceProcessGet(deviceserial)
if err != nil {
log.Fatal(err)
return
}
fmt.Println(r6)
} }
/* /*
@ -173,3 +123,130 @@ func TestOauth(t *testing.T) {
// } // }
// fmt.Println(r2) // fmt.Println(r2)
*/ */
/*
// 人员信息采集-远程采集方式
// deviceserial := "AF8534579"
// r0, err := CaptureRemoteRuleSet(deviceserial, true, 0, 50000)
// if err != nil {
// log.Fatal(err)
// return
// }
// fmt.Println(r0)
// r1, err := CaptureRemoteRuleGet(deviceserial)
// if err != nil {
// log.Fatal(err)
// return
// }
// fmt.Println(r1)
// r2, err := CaptureRemoteIDCardGet(deviceserial)
// if err != nil {
// log.Fatal(err)
// return
// }
// fmt.Println(r2)
// r3, err := CaptureRemoteCardGet(deviceserial)
// if err != nil {
// log.Fatal(err)
// return
// }
// fmt.Println(r3)
// r4, err := CaptureRemoteFingerPrintGet(deviceserial, 1)
// if err != nil {
// log.Fatal(err)
// return
// }
// fmt.Println(r4)
// r5, err := CaptureRemoteFaceGet(deviceserial, false)
// if err != nil {
// log.Fatal(err)
// return
// }
// fmt.Println(r5)
// r6, err := CaptureRemoteFaceProcessGet(deviceserial)
// if err != nil {
// log.Fatal(err)
// return
// }
// fmt.Println(r6)
*/
/*
// 人员信息采集-本地采集方式
deviceserial := "AF8534579"
r0, err := CaptureLocalRuleSet(deviceserial, true, true, []model.CaptureLocalRule{
{
DataType: "employeeNo",
Enable: true,
Length: 64,
}, {
DataType: "name",
Enable: true,
UniqueCheck: false,
Length: 4,
}, {
DataType: "fingprint",
Enable: true,
FingerPrintNos: []int{1, 2},
Number: 2,
}, {
DataType: "card",
Enable: true,
Number: 1,
Length: 4,
},
})
if err != nil {
log.Fatal(err)
return
}
fmt.Println(r0)
r1, err := CaptureLocalRuleGet(deviceserial)
if err != nil {
log.Fatal(err)
return
}
fmt.Println(r1)
r2, err := CaptureLocalPeopleCreate(deviceserial, "666", "wyh", "330821200111093616", []string{"101112"})
if err != nil {
log.Fatal(err)
return
}
fmt.Println(r2)
r3, err := CaptureLocalSearch(deviceserial, "uu67hhjjk", 0, 20, "", []string{"666"})
if err != nil {
log.Fatal(err)
return
}
fmt.Println(r3)
r4, err := CaptureLocalStatusGet(deviceserial)
if err != nil {
log.Fatal(err)
return
}
fmt.Println(r4)
r5, err := CaptureLocalDeleteAll(deviceserial)
if err != nil {
log.Fatal(err)
return
}
fmt.Println(r5)
r6, err := CaptureLocalDeleteByEmployeeNos(deviceserial, []string{"666"})
if err != nil {
log.Fatal(err)
return
}
fmt.Println(r6)
*/