人脸管理模块 complete
This commit is contained in:
parent
f2cdfefb5e
commit
5e7857502a
|
|
@ -0,0 +1,36 @@
|
||||||
|
package model
|
||||||
|
|
||||||
|
type PersonCreateData struct {
|
||||||
|
Person
|
||||||
|
DynamicCode string `json:"dynamicCode"`
|
||||||
|
MaxOpenDoorTime int `json:"maxOpenDoorTime"`
|
||||||
|
CallNumbers []string `json:"callNumbers"`
|
||||||
|
FloorNumbers []int `json:"floorNumbers"`
|
||||||
|
LocalUIRight int `json:"localUIRight"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type PersonReq struct {
|
||||||
|
EmployeeNo string `json:"employeeNo"` //编号,必填
|
||||||
|
PersonName string `json:"personName"` //姓名,必填
|
||||||
|
PersonPhone string `json:"personPhone"`
|
||||||
|
FaceImageBase64 string `json:"faceImageBase64"`
|
||||||
|
VerifyImage bool `json:"verifyImage"` //是否进行人脸质量校验,默认true
|
||||||
|
}
|
||||||
|
|
||||||
|
type PersonOperation struct {
|
||||||
|
PersonStatisticsId string `json:"personStatisticsId"`
|
||||||
|
FaceStatisticsId string `json:"faceStatisticsId"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Person struct {
|
||||||
|
EmployeeNo string `json:"employeeNo"`
|
||||||
|
PersonName string `json:"personName"`
|
||||||
|
PersonPhone string `json:"personPhone"`
|
||||||
|
FaceUrl string `json:"faceUrl"`
|
||||||
|
PersonType string `json:"personType"`
|
||||||
|
FloorNo int `json:"floorNo"`
|
||||||
|
RoomNo int `json:"roomNo"`
|
||||||
|
ValidBeginTime string `json:"validBeginTime"`
|
||||||
|
ValidEndTime string `json:"validEndTime"`
|
||||||
|
PlanTemplateNos []int `json:"planTemplateNos"`
|
||||||
|
}
|
||||||
|
|
@ -1,18 +1,37 @@
|
||||||
package iot
|
package iot
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestOauth(t *testing.T) {
|
func TestOauth(t *testing.T) {
|
||||||
// serial := "AF8534579"
|
imgfile, err := os.ReadFile("../image.jpg")
|
||||||
// accesstoken := "a08a8044-3770-41f5-b5a5-048004a723ac"
|
if err != nil {
|
||||||
result, err := DeivceList("02", 1, 20)
|
log.Fatal(err.Error())
|
||||||
|
}
|
||||||
|
imgbase64 := base64.StdEncoding.EncodeToString(imgfile)
|
||||||
|
p, err := PersonDetail("02")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
fmt.Println(p)
|
||||||
fmt.Println(*result)
|
person, err := PersonFaceUpdate("02", imgbase64, true)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err.Error())
|
||||||
|
}
|
||||||
|
p, err = PersonDetail("02")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
r, err := PersonFaceDelete("02")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
fmt.Println("r ", r)
|
||||||
|
fmt.Println("p ", p)
|
||||||
|
fmt.Println("person ", person)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,205 @@
|
||||||
|
package iot
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"myschools.me/suguo/hikvision/iot/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
PERSON_BASE = "https://api2.hik-cloud.com/api/v1/open/basic/persons"
|
||||||
|
PERSON_CREATE = PERSON_BASE + "/create"
|
||||||
|
PERSON_UPDARE = PERSON_BASE + "/update"
|
||||||
|
PERSON_DELETE = PERSON_BASE + "/delete"
|
||||||
|
PERSON_DETAIL = PERSON_BASE + "/get"
|
||||||
|
|
||||||
|
PERSON_FACE_SETCFG = "https://api2.hik-cloud.com/api/v1/open/basic/tenantConfigs/actions/updateTenantConfig"
|
||||||
|
|
||||||
|
FACE_BASE = "https://api2.hik-cloud.com/api/v1/open/basic/faces"
|
||||||
|
PERSON_FACE_UPDATE = FACE_BASE + "/update"
|
||||||
|
PERSON_FACE_DELETE = FACE_BASE + "/delete"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 添加人员
|
||||||
|
func PersonCreate(employeeNo, personName, personPhone, faceImageBase64 string, verifyImage bool) (*model.PersonCreateData, error) {
|
||||||
|
req := &model.PersonReq{
|
||||||
|
EmployeeNo: employeeNo,
|
||||||
|
PersonName: personName,
|
||||||
|
PersonPhone: personPhone,
|
||||||
|
FaceImageBase64: faceImageBase64,
|
||||||
|
VerifyImage: verifyImage,
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := hikvisionRequest("POST", PERSON_CREATE, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var result = &struct {
|
||||||
|
model.Hikvision
|
||||||
|
Data model.PersonCreateData `json:"data"`
|
||||||
|
}{}
|
||||||
|
if err := json.Unmarshal(resp, &result); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if result.Code != 200 {
|
||||||
|
return nil, fmt.Errorf("result errcode:%d errmsg:%s", result.Code, result.Message)
|
||||||
|
}
|
||||||
|
return &result.Data, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新人员信息
|
||||||
|
func PersonUpdate(employeeNo, personName, personPhone, faceImageBase64 string, verifyImage bool) (*model.PersonOperation, error) {
|
||||||
|
req := &model.PersonReq{
|
||||||
|
EmployeeNo: employeeNo,
|
||||||
|
PersonName: personName,
|
||||||
|
PersonPhone: personPhone,
|
||||||
|
FaceImageBase64: faceImageBase64,
|
||||||
|
VerifyImage: verifyImage,
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := hikvisionRequest("POST", PERSON_UPDARE, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var result = &struct {
|
||||||
|
model.Hikvision
|
||||||
|
Data model.PersonOperation `json:"data"`
|
||||||
|
}{}
|
||||||
|
if err := json.Unmarshal(resp, &result); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if result.Code != 200 {
|
||||||
|
return nil, fmt.Errorf("result errcode:%d errmsg:%s", result.Code, result.Message)
|
||||||
|
}
|
||||||
|
return &result.Data, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除人员信息
|
||||||
|
func PersonDelete(employeeNo string) (*model.PersonOperation, error) {
|
||||||
|
|
||||||
|
resp, err := hikvisionRequest("POST", fmt.Sprintf("%s?employeeNo=%s", PERSON_DELETE, employeeNo), nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var result = &struct {
|
||||||
|
model.Hikvision
|
||||||
|
Data model.PersonOperation `json:"data"`
|
||||||
|
}{}
|
||||||
|
if err := json.Unmarshal(resp, &result); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if result.Code != 200 {
|
||||||
|
return nil, fmt.Errorf("result errcode:%d errmsg:%s", result.Code, result.Message)
|
||||||
|
}
|
||||||
|
return &result.Data, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获得单个人员详情
|
||||||
|
func PersonDetail(employeeNo string) (*model.Person, error) {
|
||||||
|
|
||||||
|
resp, err := hikvisionRequest("GET", fmt.Sprintf("%s?employeeNo=%s", PERSON_DETAIL, employeeNo), nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var result = &struct {
|
||||||
|
model.Hikvision
|
||||||
|
Data model.Person `json:"data"`
|
||||||
|
}{}
|
||||||
|
if err := json.Unmarshal(resp, &result); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if result.Code != 200 {
|
||||||
|
return nil, fmt.Errorf("result errcode:%d errmsg:%s", result.Code, result.Message)
|
||||||
|
}
|
||||||
|
return &result.Data, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 人脸评分标准配置接口
|
||||||
|
// 更新人员信息
|
||||||
|
func PersonUpdateTenantConfig(pointsQuality float64, eyeDistance, clearity, posePitchMin, posePitchMax, poseYawMin, poseYawMax, uncovered, totalQuality float64) (*model.Hikvision, error) {
|
||||||
|
req := &struct {
|
||||||
|
PointsQuality float64 `json:"pointsQuality"`
|
||||||
|
EyeDistance float64 `json:"eyeDistance"`
|
||||||
|
Clearity float64 `json:"clearity"`
|
||||||
|
PosePitchMin float64 `json:"posePitchMin"`
|
||||||
|
PosePitchMax float64 `json:"posePitchMax"`
|
||||||
|
PoseYawMin float64 `json:"poseYawMin"`
|
||||||
|
PoseYawMax float64 `json:"poseYawMax"`
|
||||||
|
Uncovered float64 `json:"uncovered"`
|
||||||
|
TotalQuality float64 `json:"totalQuality"`
|
||||||
|
}{
|
||||||
|
PointsQuality: pointsQuality,
|
||||||
|
EyeDistance: eyeDistance,
|
||||||
|
Clearity: clearity,
|
||||||
|
PosePitchMin: posePitchMin,
|
||||||
|
PosePitchMax: posePitchMax,
|
||||||
|
PoseYawMin: poseYawMin,
|
||||||
|
PoseYawMax: poseYawMax,
|
||||||
|
Uncovered: uncovered,
|
||||||
|
TotalQuality: totalQuality,
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := hikvisionRequest("POST", PERSON_FACE_SETCFG, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var result = &model.Hikvision{}
|
||||||
|
if err := json.Unmarshal(resp, &result); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if result.Code != 200 {
|
||||||
|
return nil, fmt.Errorf("result errcode:%d errmsg:%s", result.Code, result.Message)
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 人员人脸更新
|
||||||
|
func PersonFaceUpdate(employeeNo, faceImageBase64 string, verifyImage bool) (*model.Hikvision, error) {
|
||||||
|
req := &struct {
|
||||||
|
EmployeeNo string `json:"employeeNo"`
|
||||||
|
VerifyImage bool `json:"verifyImage"`
|
||||||
|
FaceImageBase64 string `json:"faceImageBase64"`
|
||||||
|
}{
|
||||||
|
EmployeeNo: employeeNo,
|
||||||
|
VerifyImage: verifyImage,
|
||||||
|
FaceImageBase64: faceImageBase64,
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := hikvisionRequest("POST", PERSON_FACE_UPDATE, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var result = &model.Hikvision{}
|
||||||
|
if err := json.Unmarshal(resp, &result); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if result.Code != 200 {
|
||||||
|
return nil, fmt.Errorf("result errcode:%d errmsg:%s", result.Code, result.Message)
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 人员人脸删除
|
||||||
|
func PersonFaceDelete(employeeNo string) (*model.Hikvision, error) {
|
||||||
|
|
||||||
|
resp, err := hikvisionRequest("POST", fmt.Sprintf("%s?employeeNo=%s", PERSON_FACE_DELETE, employeeNo), nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var result = &model.Hikvision{}
|
||||||
|
if err := json.Unmarshal(resp, &result); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if result.Code != 200 {
|
||||||
|
return nil, fmt.Errorf("result errcode:%d errmsg:%s", result.Code, result.Message)
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
@ -1 +1,13 @@
|
||||||
海康云眸平台IOT
|
### 海康云眸平台(iot)
|
||||||
|
|
||||||
|
```
|
||||||
|
environment:
|
||||||
|
clientID = os.Getenv("HIK_IOT_CLIENTID")
|
||||||
|
clientSecret = os.Getenv("HIK_IOT_CLIENTSECRET")
|
||||||
|
scope = os.Getenv("HIK_IOT_SCOPE")
|
||||||
|
```
|
||||||
|
- 基础管理
|
||||||
|
- - 分组管理
|
||||||
|
- - 接入管理
|
||||||
|
- - 校时配置
|
||||||
|
- - 人员管理
|
||||||
|
|
|
||||||
19
readme.md
19
readme.md
|
|
@ -1,3 +1,18 @@
|
||||||
海康SDK
|
<h1>海康SDK</h1>
|
||||||
|
|
||||||
hikvision.Init(&hikvision.Config{})
|
|
||||||
|
hikvision.Init(&hikvision.Config{})
|
||||||
|
|
||||||
|
### 1.海康云眸平台(iot)
|
||||||
|
|
||||||
|
```
|
||||||
|
environment:
|
||||||
|
clientID = os.Getenv("HIK_IOT_CLIENTID")
|
||||||
|
clientSecret = os.Getenv("HIK_IOT_CLIENTSECRET")
|
||||||
|
scope = os.Getenv("HIK_IOT_SCOPE")
|
||||||
|
```
|
||||||
|
- 基础管理
|
||||||
|
- - 分组管理
|
||||||
|
- - 接入管理
|
||||||
|
- - 校时配置
|
||||||
|
- - 人员管理
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue