Files
zmkgC/third/ws/construction.go
2025-07-07 20:11:59 +08:00

168 lines
6.1 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Package ws
// @Author 铁憨憨[cory] 2025/2/12 15:20:00
package ws
import "github.com/gorilla/websocket"
/*
============================================常量============================================
============================================常量============================================
============================================常量============================================
*/
const (
DECLARE = "declare" //设备初上线
PING = "ping" //心跳
ToClient = "to_client" // 服务器消息下发到客户端的响应
)
/*
============================================公共============================================
============================================公共============================================
============================================公共============================================
*/
// DeviceInfo 存储连接设备信息
type DeviceInfo struct {
IP string `json:"ip"`
Port string `json:"port"`
Conn *websocket.Conn `json:"conn"`
}
// GenericMessage 通用消息结构,用于解析初始的 cmd 字段
type GenericMessage struct {
CMD string `json:"cmd"`
}
// CommonResponse 公共响应结构
type CommonResponse struct {
Cmd string `json:"cmd"`
From string `json:"from"`
To string `json:"to"`
//Extra string `json:"extra"`
Data CommonResponseData `json:"data"`
}
type CommonResponseData struct {
Cmd string `json:"cmd"`
UserIds []string `json:"userIds" dc:"用户IDS"`
UserID string `json:"user_id"`
Code int `json:"code"`
Msg string `json:"msg"`
DelFailed []DelMultiUserData `json:"delFailed"`
}
type DelMultiUserData struct {
UserID string `json:"user_id"`
Code int `json:"code"`
Msg string `json:"msg"`
}
/*
============================================基础============================================
============================================基础============================================
============================================基础============================================
*/
// DeclareMessage 设备上线消息
type DeclareMessage struct {
Cmd string `json:"cmd"`
Type string `json:"type"`
SN string `json:"sn"`
VersionCode string `json:"version_code"`
VersionName string `json:"version_name"`
Token string `json:"token"`
Ip string `json:"ip"`
Timestamp float64 `json:"timestamp"`
}
type PongMessage struct {
Cmd string `json:"cmd"`
From string `json:"from"`
To string `json:"to"`
Data PongMessageData `json:"data"`
}
// PongMessageData 心跳回复消息结构
type PongMessageData struct {
Cmd string `json:"cmd"`
}
/*
============================================ws请求============================================
============================================ws请求============================================
============================================ws请求============================================
*/
// PeopleInformation 人员信息下发
type PeopleInformation struct {
Cmd string `json:"cmd"` //该接口固定为to_device
From string `json:"from"` //可不填写,填写uuid来做为发送请求或响应的标识
To string `json:"to"` //设备号(请查看公共设置中的设备号)
//Extra string `json:"extra"` //给服务端预留的补充字段,设备端不处理这个字段内容。设备在响应这条指令时原样返回
Data PeopleInData `json:"data"`
}
type PeopleInData struct {
Cmd string `json:"cmd"`
UserID string `json:"user_id"`
Name string `json:"name"`
FaceTemplate string `json:"face_template"` // http 链接图
IDValid string `json:"id_valid"` // 人员有效期人员在这个时间点后无法通行格式yyyy-MM-dd 或者 yyyy-MM-dd HH:mm为 “” 则为永久
}
// DeletionOfPersonnel 删除人员
type DeletionOfPersonnel struct {
Cmd string `json:"cmd"`
From string `json:"from"`
To string `json:"to"`
Data DeletionOfPersonnelData `json:"data"`
}
type DeletionOfPersonnelData struct {
Cmd string `json:"cmd"`
UserID string `json:"user_id"`
UserType int `json:"user_type"` // 删除的用户类型0-人脸接口下发的数据 1-人证比对接口下发的数据
}
// BatchDeletion 批量删除
type BatchDeletion struct {
Cmd string `json:"cmd"`
From string `json:"from"`
To string `json:"to"`
Data BatchDeletionData `json:"data"`
}
type BatchDeletionData struct {
Cmd string `json:"cmd"`
UserIds []string `json:"user_ids"`
UserType int `json:"user_type"` // 删除的用户类型0-人脸接口下发的数据 1-人证比对接口下发的数据
}
// DeletionALlOfPersonnel 删除全部人员
type DeletionALlOfPersonnel struct {
Cmd string `json:"cmd"`
From string `json:"from"`
To string `json:"to"`
Data DeletionALlOfPersonnelData `json:"data"`
}
type DeletionALlOfPersonnelData struct {
Cmd string `json:"cmd"`
UserType int `json:"user_type"` // 删除的用户类型0-人脸接口下发的数据 1-人证比对接口下发的数据
}
// PersonnelInformationAcquisition 人员信息获取
type PersonnelInformationAcquisition struct {
Cmd string `json:"cmd"` //该接口固定为to_device
From string `json:"from"` //可不填写,填写uuid来做为发送请求或响应的标识
To string `json:"to"` //设备号(请查看公共设置中的设备号)
Data PersonnelInformationAcquisitionTwo `json:"data"`
}
type PersonnelInformationAcquisitionTwo struct {
Cmd string `json:"cmd"`
Value int `json:"value"`
}
/*
============================================http请求============================================
============================================http请求============================================
============================================http请求============================================
*/
//loggerMiddlewareloggerMiddlewareloggerMiddleware