This commit is contained in:
@@ -5,165 +5,66 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/pkg/errors"
|
||||
"github.com/bytedance/sonic"
|
||||
)
|
||||
|
||||
// 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 至少需要一个")
|
||||
}
|
||||
|
||||
params := make(map[string]interface{})
|
||||
if req.CardNo != "" {
|
||||
params["cardNo"] = req.CardNo
|
||||
}
|
||||
if req.DeviceID != "" {
|
||||
params["deviceId"] = req.DeviceID
|
||||
}
|
||||
|
||||
businessData := map[string]interface{}{
|
||||
"params": params,
|
||||
}
|
||||
|
||||
resp, err := c.doRequest(ctx, "/device/info", businessData)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result DeviceInfoResp
|
||||
if err := sonic.Unmarshal(resp, &result); err != nil {
|
||||
return nil, errors.Wrap(errors.CodeGatewayInvalidResp, err, "解析设备信息响应失败")
|
||||
}
|
||||
|
||||
return &result, nil
|
||||
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 至少需要一个")
|
||||
}
|
||||
|
||||
params := make(map[string]interface{})
|
||||
if req.CardNo != "" {
|
||||
params["cardNo"] = req.CardNo
|
||||
}
|
||||
if req.DeviceID != "" {
|
||||
params["deviceId"] = req.DeviceID
|
||||
}
|
||||
|
||||
businessData := map[string]interface{}{
|
||||
"params": params,
|
||||
}
|
||||
|
||||
resp, err := c.doRequest(ctx, "/device/slot-info", businessData)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result SlotInfoResp
|
||||
if err := sonic.Unmarshal(resp, &result); err != nil {
|
||||
return nil, errors.Wrap(errors.CodeGatewayInvalidResp, err, "解析卡槽信息响应失败")
|
||||
}
|
||||
|
||||
return &result, nil
|
||||
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 {
|
||||
params := map[string]interface{}{
|
||||
"deviceId": req.DeviceID,
|
||||
"uploadSpeed": req.UploadSpeed,
|
||||
"downloadSpeed": req.DownloadSpeed,
|
||||
}
|
||||
if req.Extend != "" {
|
||||
params["extend"] = req.Extend
|
||||
}
|
||||
|
||||
businessData := map[string]interface{}{
|
||||
"params": params,
|
||||
}
|
||||
|
||||
_, err := c.doRequest(ctx, "/device/speed-limit", businessData)
|
||||
_, err := c.doRequest(ctx, "/device/speed-limit", req)
|
||||
return err
|
||||
}
|
||||
|
||||
// SetWiFi 设置设备 WiFi
|
||||
// 设置设备的 WiFi 名称、密码和启用状态
|
||||
// 配置 WiFi 名称、密码及启用状态,cardNo(ICCID)为必填参数
|
||||
// POST /device/wifi-config
|
||||
func (c *Client) SetWiFi(ctx context.Context, req *WiFiReq) error {
|
||||
params := map[string]interface{}{
|
||||
"deviceId": req.DeviceID,
|
||||
"ssid": req.SSID,
|
||||
"password": req.Password,
|
||||
"enabled": req.Enabled,
|
||||
}
|
||||
if req.Extend != "" {
|
||||
params["extend"] = req.Extend
|
||||
}
|
||||
|
||||
businessData := map[string]interface{}{
|
||||
"params": params,
|
||||
}
|
||||
|
||||
_, err := c.doRequest(ctx, "/device/wifi", businessData)
|
||||
_, 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 {
|
||||
params := map[string]interface{}{
|
||||
"deviceId": req.DeviceID,
|
||||
"targetIccid": req.TargetICCID,
|
||||
}
|
||||
if req.Extend != "" {
|
||||
params["extend"] = req.Extend
|
||||
}
|
||||
|
||||
businessData := map[string]interface{}{
|
||||
"params": params,
|
||||
}
|
||||
|
||||
_, err := c.doRequest(ctx, "/device/switch-card", businessData)
|
||||
// 强制设置 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 {
|
||||
params := map[string]interface{}{
|
||||
"deviceId": req.DeviceID,
|
||||
}
|
||||
if req.Extend != "" {
|
||||
params["extend"] = req.Extend
|
||||
}
|
||||
|
||||
businessData := map[string]interface{}{
|
||||
"params": params,
|
||||
}
|
||||
|
||||
_, err := c.doRequest(ctx, "/device/reset", businessData)
|
||||
_, err := c.doRequest(ctx, "/device/factory-reset", req)
|
||||
return err
|
||||
}
|
||||
|
||||
// RebootDevice 设备重启
|
||||
// 远程重启设备
|
||||
// POST /device/restart
|
||||
func (c *Client) RebootDevice(ctx context.Context, req *DeviceOperationReq) error {
|
||||
params := map[string]interface{}{
|
||||
"deviceId": req.DeviceID,
|
||||
}
|
||||
if req.Extend != "" {
|
||||
params["extend"] = req.Extend
|
||||
}
|
||||
|
||||
businessData := map[string]interface{}{
|
||||
"params": params,
|
||||
}
|
||||
|
||||
_, err := c.doRequest(ctx, "/device/reboot", businessData)
|
||||
_, err := c.doRequest(ctx, "/device/restart", req)
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user