All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m40s
89 lines
3.1 KiB
Go
89 lines
3.1 KiB
Go
// Package gateway 提供设备相关的 8 个 API 方法封装
|
||
package gateway
|
||
|
||
import (
|
||
"context"
|
||
|
||
"github.com/break/junhong_cmp_fiber/pkg/errors"
|
||
)
|
||
|
||
// GetDeviceInfo 获取设备信息
|
||
// 通过卡号或设备 ID 查询设备的在线状态、信号强度、WiFi 信息等
|
||
// POST /device/info
|
||
func (c *Client) GetDeviceInfo(ctx context.Context, req *DeviceInfoReq) (*DeviceInfoResp, error) {
|
||
if req.CardNo == "" && req.DeviceID == "" {
|
||
return nil, errors.New(errors.CodeInvalidParam, "cardNo 和 deviceId 至少需要一个")
|
||
}
|
||
return doRequestWithResponse[DeviceInfoResp](c, ctx, "/device/info", req)
|
||
}
|
||
|
||
// GetSlotInfo 获取设备卡槽信息
|
||
// 查询设备的所有卡槽及其中的卡信息
|
||
// POST /device/slot-info
|
||
func (c *Client) GetSlotInfo(ctx context.Context, req *DeviceInfoReq) (*SlotInfoResp, error) {
|
||
if req.CardNo == "" && req.DeviceID == "" {
|
||
return nil, errors.New(errors.CodeInvalidParam, "cardNo 和 deviceId 至少需要一个")
|
||
}
|
||
return doRequestWithResponse[SlotInfoResp](c, ctx, "/device/slot-info", req)
|
||
}
|
||
|
||
// SetSpeedLimit 设置设备限速
|
||
// 设置设备的统一限速值(单位 KB/s)
|
||
// POST /device/speed-limit
|
||
func (c *Client) SetSpeedLimit(ctx context.Context, req *SpeedLimitReq) error {
|
||
_, err := c.doRequest(ctx, "/device/speed-limit", req)
|
||
return err
|
||
}
|
||
|
||
// SetWiFi 设置设备 WiFi
|
||
// Gateway 实际要求 cardNo 传设备 IMEI,并搭配内层 params 下发 WiFi 名称和密码
|
||
// POST /device/wifi-config
|
||
func (c *Client) SetWiFi(ctx context.Context, req *WiFiReq) error {
|
||
_, err := c.doRequest(ctx, "/device/wifi-config", req)
|
||
return err
|
||
}
|
||
|
||
// SwitchCard 设备切换卡
|
||
// 为多卡设备切换到目标 ICCID,operationType 固定为 2
|
||
// POST /device/card-switch
|
||
func (c *Client) SwitchCard(ctx context.Context, req *SwitchCardReq) error {
|
||
// 强制设置 operationType 为 2(切卡操作)
|
||
req.OperationType = 2
|
||
_, err := c.doRequest(ctx, "/device/card-switch", req)
|
||
return err
|
||
}
|
||
|
||
// ResetDevice 设备恢复出厂设置
|
||
// 将设备恢复到出厂设置状态
|
||
// POST /device/factory-reset
|
||
func (c *Client) ResetDevice(ctx context.Context, req *DeviceOperationReq) error {
|
||
_, err := c.doRequest(ctx, "/device/factory-reset", req)
|
||
return err
|
||
}
|
||
|
||
// RebootDevice 设备重启
|
||
// 远程重启设备
|
||
// POST /device/restart
|
||
func (c *Client) RebootDevice(ctx context.Context, req *DeviceOperationReq) error {
|
||
_, err := c.doRequest(ctx, "/device/restart", req)
|
||
return err
|
||
}
|
||
|
||
// SwitchMode 设置设备切卡模式
|
||
// 切换设备卡槽的自动/手动模式,0=自动切卡,1=手动切卡
|
||
// POST /device/SwitchMode
|
||
func (c *Client) SwitchMode(ctx context.Context, req *SwitchModeReq) error {
|
||
_, err := c.doRequest(ctx, "/device/SwitchMode", req)
|
||
return err
|
||
}
|
||
|
||
// SyncDeviceInfo 同步查询设备信息(直接返回,无需回调)
|
||
// 与异步 /device/info 的区别:直接返回全量数据,无需 callbackUrl
|
||
// POST /device/sync-info
|
||
func (c *Client) SyncDeviceInfo(ctx context.Context, req *SyncDeviceInfoReq) (*SyncDeviceInfoResp, error) {
|
||
if req.CardNo == "" {
|
||
return nil, errors.New(errors.CodeInvalidParam, "cardNo 不能为空")
|
||
}
|
||
return doRequestWithResponse[SyncDeviceInfoResp](c, ctx, "/device/sync-info", req)
|
||
}
|