This commit is contained in:
2025-07-07 20:11:59 +08:00
parent ab0fdbc447
commit 06e3aa2eb3
2009 changed files with 193082 additions and 0 deletions

View File

@ -0,0 +1,4 @@
package guiji_back5
type GuijiBack struct {
}

View File

@ -0,0 +1,117 @@
package guiji_back5
import (
"bytes"
"context"
"encoding/json"
"github.com/gogf/gf/v2/frame/g"
"github.com/tiger1103/gfast/v3/api/constant"
"io/ioutil"
"net/http"
"strconv"
)
// 请求参数结构体【这里传时间】
type GetDevicesOnlineTimeDaysReq struct {
g.Meta `path:"/guijiDate" method:"post" tags:"视频安全帽相关" summary:"获取指定时间戳范围内帽子的在线时间"`
UID string `json:"uid" dc:"平台的用户ID"`
Stime int64 `json:"stime" dc:"Unix开始时间戳"`
Etime int64 `json:"etime" dc:"Unix结束时间戳"`
}
type DevicesOnlineTimeDaysReq struct {
AdminID string `json:"admin_id"`
UserID string `json:"user_id"`
Stime int64 `json:"stime"`
Etime int64 `json:"etime"`
Token string `json:"token"`
}
type DataListItem struct {
Ctime string `json:"ctime"`
Ltime int `json:"ltime"`
Sec int `json:"sec"`
}
// 完整响应结构体
type GetDevicesOnlineTimeDaysRes struct {
Status bool `json:"status"`
Msg string `json:"msg"`
Data DataResponse `json:"data"`
MsgCode string `json:"msg_code"`
}
// 响应中的数据部分结构体
type DataResponse struct {
List []DataListItem `json:"list"`
Total int `json:"total"`
TotalText string `json:"total_text"`
}
// GetDevicesOnlineTimeDays是用于获取设备在线时间的方法
func (gui GuijiBack) GetDevicesOnlineTimeDays(ctx context.Context, req *GetDevicesOnlineTimeDaysReq) (res *GetDevicesOnlineTimeDaysRes, err error) {
res = new(GetDevicesOnlineTimeDaysRes)
dataReq := DevicesOnlineTimeDaysReq{
AdminID: constant.AdminId,
UserID: req.UID,
Stime: req.Stime,
Etime: req.Etime,
Token: constant.Token,
}
reqBody, err := json.Marshal(dataReq)
if err != nil {
return res, err
}
// 发送POST请求
resp, err := http.Post("https://caps.runde.pro/api/index.php?ctl=device&act=get_devices_online_time_days", "application/json", bytes.NewBuffer(reqBody))
if err != nil {
return res, err
}
defer resp.Body.Close()
// 读取响应体
respBody, err := ioutil.ReadAll(resp.Body)
if err != nil {
return res, err
}
// 反序列化响应体到结构体
err = json.Unmarshal(respBody, &res)
if err != nil {
return res, err
}
return res, nil
}
// 自定义UnmarshalJSON方法来处理sec字段的不同数据类型【小杨源码改写】
func (d *DataListItem) UnmarshalJSON(data []byte) error {
// 创建一个只在此方法内使用的类型以避免无限递归调用UnmarshalJSON
type Alias DataListItem
aux := &struct {
Sec json.RawMessage `json:"sec"`
*Alias
}{
Alias: (*Alias)(d),
}
if err := json.Unmarshal(data, &aux); err != nil {
return err
}
// 尝试将sec解析为int
if err := json.Unmarshal(aux.Sec, &d.Sec); err != nil {
// 如果解析为int失败尝试解析为string然后转换为int
var secStr string
if err := json.Unmarshal(aux.Sec, &secStr); err != nil {
return err // 不能解析sec为int或string
}
secInt, err := strconv.Atoi(secStr)
if err != nil {
return err // 不能将sec的字符串值转换为int
}
d.Sec = secInt
}
return nil
}

View File

@ -0,0 +1,77 @@
package guiji_back5
import (
"bytes"
"context"
"encoding/json"
"github.com/gogf/gf/v2/frame/g"
"github.com/tiger1103/gfast/v3/api/constant"
"io/ioutil"
"net/http"
)
type GetUserPathWebReq struct {
g.Meta `path:"/guijiData" method:"post" tags:"视频安全帽相关" summary:"获取指定时间段内轨迹记录"`
UID string `json:"uid" dc:"平台的用户ID"`
Start int64 `json:"start" dc:"Unix开始时间戳"`
End int64 `json:"end" dc:"Unix结束时间戳"`
}
type UserPathWebRequest struct {
AdminID string `json:"admin_id"`
UserID string `json:"user_id"`
Start int64 `json:"start"`
End int64 `json:"end"`
Token string `json:"token"`
}
type GetUserPathWebRes struct {
Status bool `json:"status"`
Msg string `json:"msg"`
Data []PathDataItem `json:"data"`
MsgCode string `json:"msg_code"`
}
type PathDataItem struct {
XPoint string `json:"x_point"`
YPoint string `json:"y_point"`
Time string `json:"time"`
CTime string `json:"c_time"`
CAngle string `json:"c_angle"`
CSpeed string `json:"c_speed"`
CTrust string `json:"c_trust"`
GPS string `json:"gps"`
}
func (gj GuijiBack) GetUserPathWeb(ctx context.Context, req *GetUserPathWebReq) (res *GetUserPathWebRes, err error) {
res = new(GetUserPathWebRes)
dataReq := UserPathWebRequest{
AdminID: constant.AdminId,
UserID: req.UID,
Start: req.Start,
End: req.End,
Token: constant.Token,
}
reqBody, err := json.Marshal(dataReq)
// 替换为实际的API URL
url := "https://caps.runde.pro/api/index.php?ctl=location&act=get_user_path_web"
resp, err := http.Post(url, "application/json", bytes.NewBuffer(reqBody))
if err != nil {
return res, err
}
defer resp.Body.Close()
respBody, err := ioutil.ReadAll(resp.Body)
if err != nil {
return res, err
}
err = json.Unmarshal(respBody, &res)
if err != nil {
return nil, err
}
return res, nil
}