Compare commits
2 Commits
5e7857502a
...
3fd6f52a1e
| Author | SHA1 | Date |
|---|---|---|
|
|
3fd6f52a1e | |
|
|
ac6cc166ef |
|
|
@ -0,0 +1,84 @@
|
|||
package iot
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"myschools.me/suguo/hikvision/iot/model"
|
||||
)
|
||||
|
||||
const (
|
||||
CARD_BASE = "https://api2.hik-cloud.com/api/v1/open/basic/cards"
|
||||
CARD_CREATE = CARD_BASE + "/batchCreate"
|
||||
CARD_DELETE = CARD_BASE + "/batchDelete"
|
||||
CARD_DELETE_CARDS = CARD_BASE + "/deletePersonCards"
|
||||
)
|
||||
|
||||
// 新增卡片
|
||||
func CardCreate(cards []model.CardCreateReq) (*model.Hikvision, error) {
|
||||
req := &struct{ Cards []model.CardCreateReq }{
|
||||
Cards: cards,
|
||||
}
|
||||
|
||||
resp, err := hikvisionRequest("POST", CARD_CREATE, 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 CardDelete(cardNos []string) (*model.Hikvision, error) {
|
||||
req := &struct {
|
||||
CardNos []string `json:"cardNos"`
|
||||
}{
|
||||
CardNos: cardNos,
|
||||
}
|
||||
|
||||
resp, err := hikvisionRequest("POST", CARD_DELETE, 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 CardDeleteByEmployeeNo(employeeNo string, cardNos []string) (*model.Hikvision, error) {
|
||||
req := &struct {
|
||||
EmployeeNo string `json:"employeeNo"`
|
||||
CardNos []string `json:"cardNos"`
|
||||
}{
|
||||
EmployeeNo: employeeNo,
|
||||
CardNos: cardNos,
|
||||
}
|
||||
|
||||
resp, err := hikvisionRequest("POST", CARD_DELETE_CARDS, 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
|
||||
}
|
||||
|
|
@ -31,7 +31,7 @@ const (
|
|||
// 注册设备到对应分组内。
|
||||
//
|
||||
// 注册设备时首先会将设备添加到平台,然后异步同步设备通道。如果设备添加成功而同步设备通道失败,则可以先获取设备列表信息,再手动调用通道同步接口同步设备下的通道。\
|
||||
func DeivceRegister(deviceserial, groupno, validatecode string) (*model.DeviceData, error) {
|
||||
func DeviceRegister(deviceserial, groupno, validatecode string) (*model.DeviceData, error) {
|
||||
|
||||
req := &struct {
|
||||
DeviceSerial string `json:"deviceSerial"` //设备序列号
|
||||
|
|
@ -63,7 +63,7 @@ func DeivceRegister(deviceserial, groupno, validatecode string) (*model.DeviceDa
|
|||
}
|
||||
|
||||
// 从某一分组内删除设备
|
||||
func DeivceDelete(deviceSerial string) (*model.Hikvision, error) {
|
||||
func DeviceDelete(deviceSerial string) (*model.Hikvision, error) {
|
||||
resp, err := hikvisionRequest("POST", fmt.Sprintf("%s?deviceSerial=%s", ACCESS_DELETE, deviceSerial), nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -80,7 +80,7 @@ func DeivceDelete(deviceSerial string) (*model.Hikvision, error) {
|
|||
}
|
||||
|
||||
// 该接口用于修改设备名称
|
||||
func DeivceUpdate(deviceserial, devicename string) (*model.Hikvision, error) {
|
||||
func DeviceUpdate(deviceserial, devicename string) (*model.Hikvision, error) {
|
||||
|
||||
req := &struct {
|
||||
DeviceSerial string `json:"deviceSerial"` //设备序列号
|
||||
|
|
@ -106,7 +106,7 @@ func DeivceUpdate(deviceserial, devicename string) (*model.Hikvision, error) {
|
|||
}
|
||||
|
||||
// 该接口用于根据设备序列号获取单个设备详细信息
|
||||
func DeivceDetail(deviceSerial string) (*model.DeviceData, error) {
|
||||
func DeviceDetail(deviceSerial string) (*model.DeviceData, error) {
|
||||
resp, err := hikvisionRequest("GET", fmt.Sprintf("%s?deviceSerial=%s", ACCESS_DETAIL, deviceSerial), nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -126,7 +126,7 @@ func DeivceDetail(deviceSerial string) (*model.DeviceData, error) {
|
|||
}
|
||||
|
||||
// 该接口用于查询某组下设备列表信息 ,组编号,页数,页行数
|
||||
func DeivceList(groupno string, pageno, pagesize int) (*model.DeivceListData, error) {
|
||||
func DeviceList(groupno string, pageno, pagesize int) (*model.DeviceListData, error) {
|
||||
url := fmt.Sprintf("%s?groupNo=%s&pageNo=%d&pageSize=%d", ACCESS_LIST, groupno, pageno, pagesize)
|
||||
resp, err := hikvisionRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
|
|
@ -134,7 +134,7 @@ func DeivceList(groupno string, pageno, pagesize int) (*model.DeivceListData, er
|
|||
}
|
||||
var result = &struct {
|
||||
model.Hikvision
|
||||
Data model.DeivceListData `json:"data"`
|
||||
Data model.DeviceListData `json:"data"`
|
||||
}{}
|
||||
if err := json.Unmarshal(resp, &result); err != nil {
|
||||
return nil, err
|
||||
|
|
@ -147,7 +147,7 @@ func DeivceList(groupno string, pageno, pagesize int) (*model.DeivceListData, er
|
|||
}
|
||||
|
||||
// 该接口用于获取用户接入的设备总数
|
||||
func DeivceNum() (*int, error) {
|
||||
func DeviceNum() (*int, error) {
|
||||
|
||||
resp, err := hikvisionRequest("GET", ACCESS_ACCOUNT, nil)
|
||||
if err != nil {
|
||||
|
|
@ -170,7 +170,7 @@ func DeivceNum() (*int, error) {
|
|||
}
|
||||
|
||||
// 该接口用于查询设备的状态信息,目前仅支持萤石设备 /*测试未通过*/
|
||||
func DeivceStatus(deviceserial string) (*model.DeivceStatusData, error) {
|
||||
func DeviceStatus(deviceserial string) (*model.DeviceStatusData, error) {
|
||||
|
||||
resp, err := hikvisionRequest("GET", fmt.Sprintf("%s?deviceSerial=%s", ACCESS_STATUS, deviceserial), nil)
|
||||
if err != nil {
|
||||
|
|
@ -178,7 +178,7 @@ func DeivceStatus(deviceserial string) (*model.DeivceStatusData, error) {
|
|||
}
|
||||
var result = &struct {
|
||||
model.Hikvision
|
||||
Data model.DeivceStatusData `json:"data"`
|
||||
Data model.DeviceStatusData `json:"data"`
|
||||
}{}
|
||||
if err := json.Unmarshal(resp, &result); err != nil {
|
||||
return nil, err
|
||||
|
|
@ -191,7 +191,7 @@ func DeivceStatus(deviceserial string) (*model.DeivceStatusData, error) {
|
|||
}
|
||||
|
||||
// 该接口用于重启设备,请谨慎操作
|
||||
func DeivceReboot(deviceserial string) (*model.Hikvision, error) {
|
||||
func DeviceReboot(deviceserial string) (*model.Hikvision, error) {
|
||||
params := &struct {
|
||||
DeviceSerial string `json:"deviceSerial"`
|
||||
}{
|
||||
|
|
@ -223,8 +223,8 @@ func DeivceReboot(deviceserial string) (*model.Hikvision, error) {
|
|||
注册设备接口返回内容code=60058时,需要进行设备确权操作。
|
||||
*/
|
||||
|
||||
// 下线确认
|
||||
func DeivceOffline(deviceserial string) (*model.Hikvision, error) {
|
||||
// 下线确认 errcode:20002003 errmsg:离线失败
|
||||
func DeviceOffline(deviceserial string) (*model.Hikvision, error) {
|
||||
|
||||
resp, err := hikvisionRequest("GET", fmt.Sprintf("https://api2.hik-cloud.com/v1/carrier/wing/endpoint/confirm/right/offlineconfirm?deviceSerial=%s", deviceserial), nil)
|
||||
if err != nil {
|
||||
|
|
@ -242,7 +242,7 @@ func DeivceOffline(deviceserial string) (*model.Hikvision, error) {
|
|||
}
|
||||
|
||||
// 上线线确认
|
||||
func DeivceOnline(deviceserial string) (*model.Hikvision, error) {
|
||||
func DeviceOnline(deviceserial string) (*model.Hikvision, error) {
|
||||
|
||||
resp, err := hikvisionRequest("GET", fmt.Sprintf("https://api2.hik-cloud.com/v1/carrier/wing/endpoint/confirm/right/onlineconfirm?deviceSerial=%s", deviceserial), nil)
|
||||
if err != nil {
|
||||
|
|
@ -374,7 +374,7 @@ func DeviceGetNTPServerCfg(deviceserial string, ntpserverid int) (*model.DeviceS
|
|||
}
|
||||
|
||||
// 该接口用于配置设备指定NTP服务器参数
|
||||
func DeviceSetNTPServerCfg(req model.DeviceSetNTPServerCfgReq) (*model.Hikvision, error) {
|
||||
func DeviceSetNTPServerCfg(req *model.DeviceSetNTPServerCfgReq) (*model.Hikvision, error) {
|
||||
resp, err := hikvisionRequest("POST", TIM_NTPSERVER_CFG, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import (
|
|||
const (
|
||||
/*设备分组管理*/
|
||||
GROUP_BASE = "https://api2.hik-cloud.com/api/v1/open/basic/groups"
|
||||
GROUP_ADD = GROUP_BASE + "/create"
|
||||
GROUP_CREATE = GROUP_BASE + "/create"
|
||||
GROUP_REMOVE = GROUP_BASE + "/delete"
|
||||
GROUP_UPDATE = GROUP_BASE + "/update"
|
||||
GROUP_DETAIL = GROUP_BASE + "/get"
|
||||
|
|
@ -23,7 +23,7 @@ const (
|
|||
)
|
||||
|
||||
// 该接口用于通过编号来新增组。最多支持3000个组,最多支持5层嵌套。
|
||||
func GroupAdd(groupname, groupno, parentno string) (*model.Hikvision, error) {
|
||||
func GroupCreate(groupname, groupno, parentno string) (*model.Hikvision, error) {
|
||||
|
||||
req := &struct {
|
||||
GroupName string `json:"groupName"` //组名称
|
||||
|
|
@ -35,7 +35,7 @@ func GroupAdd(groupname, groupno, parentno string) (*model.Hikvision, error) {
|
|||
ParentNo: parentno,
|
||||
}
|
||||
|
||||
resp, err := hikvisionRequest("POST", GROUP_ADD, req)
|
||||
resp, err := hikvisionRequest("POST", GROUP_CREATE, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
package model
|
||||
|
||||
type CardCreateReq struct {
|
||||
CardNo string `json:"cardNo"`
|
||||
CardType string `json:"cardType"`
|
||||
EmployeeNo string `json:"employeeNo"`
|
||||
}
|
||||
|
|
@ -13,14 +13,14 @@ type DeviceData struct {
|
|||
DeviceVersion string `json:"deviceVersion"`
|
||||
}
|
||||
|
||||
type DeivceListData struct {
|
||||
type DeviceListData struct {
|
||||
PageNo int `json:"pageNo"`
|
||||
PageSize int `json:"pageSize"`
|
||||
Total int `json:"total"`
|
||||
Rows []DeviceData `json:"rows"`
|
||||
}
|
||||
|
||||
type DeivceStatusData struct {
|
||||
type DeviceStatusData struct {
|
||||
PrivacyStatus int `json:"privacyStatus"`
|
||||
PirStatus int `json:"pirStatus"`
|
||||
AlarmSoundMode int `json:"alarmSoundMode"`
|
||||
|
|
|
|||
|
|
@ -1,14 +1,88 @@
|
|||
package iot
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestOauth(t *testing.T) {
|
||||
// g1, err := GroupGetAll()
|
||||
// if err != nil {
|
||||
// log.Println(err)
|
||||
// return
|
||||
// }
|
||||
|
||||
// fmt.Println(g1)
|
||||
|
||||
data, err := GroupDetail("02")
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println(data)
|
||||
// data, err := DeviceRegister("AF8534579", "02", "213222")
|
||||
// if err != nil {
|
||||
// log.Println(err)
|
||||
// return
|
||||
// }
|
||||
|
||||
// fmt.Println(data)
|
||||
|
||||
// result, err := DeviceSetNTPCfg("AF8534579", &model.DeviceSetNTPCfgServer{
|
||||
// Id: "1",
|
||||
// AddressingFormatType: "hostname",
|
||||
// HostName: "time.ys7.com",
|
||||
// IpAddress: "",
|
||||
// PortNo: 123,
|
||||
// SynchronizeInterval: 60,
|
||||
// })
|
||||
// if err != nil {
|
||||
// log.Println(err)
|
||||
// return
|
||||
// }
|
||||
// fmt.Println(*result)
|
||||
// q, err := DeviceSetNTPServerCfg(&model.DeviceSetNTPServerCfgReq{
|
||||
// DeviceSerial: "AF8534579",
|
||||
// NtpServerID: 1,
|
||||
// NtpServer: model.DeviceSetNTPCfgServer{
|
||||
// Id: "1",
|
||||
// AddressingFormatType: "hostname",
|
||||
// HostName: "time.ys7.com",
|
||||
// IpAddress: "",
|
||||
// PortNo: 123,
|
||||
// SynchronizeInterval: 60,
|
||||
// },
|
||||
// })
|
||||
// if err != nil {
|
||||
// log.Println(err)
|
||||
// return
|
||||
// }
|
||||
|
||||
// res, err := DeviceGetNTPServerCfg("AF8534579", 1)
|
||||
|
||||
// fmt.Println(res)
|
||||
// fmt.Println(q)
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
result, err := CardCreate([]model.CardCreateReq{{
|
||||
CardNo: "004",
|
||||
CardType: "normalCard",
|
||||
EmployeeNo: "02",
|
||||
}, {
|
||||
CardNo: "005",
|
||||
CardType: "normalCard",
|
||||
EmployeeNo: "02",
|
||||
}})
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
}
|
||||
|
||||
fmt.Println("person ", result)
|
||||
|
||||
imgfile, err := os.ReadFile("../image.jpg")
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
|
|
@ -31,7 +105,7 @@ func TestOauth(t *testing.T) {
|
|||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Println("r ", r)
|
||||
fmt.Println("p ", p)
|
||||
fmt.Println("person ", person)
|
||||
}
|
||||
fmt.Println(r)
|
||||
fmt.Println(p)
|
||||
fmt.Println(person)
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in New Issue