修复设备WiFi上游请求参数
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m40s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m40s
This commit is contained in:
@@ -36,7 +36,7 @@ func (c *Client) SetSpeedLimit(ctx context.Context, req *SpeedLimitReq) error {
|
||||
}
|
||||
|
||||
// SetWiFi 设置设备 WiFi
|
||||
// 配置 WiFi 名称、密码及启用状态,cardNo(ICCID)为必填参数
|
||||
// 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)
|
||||
|
||||
@@ -162,14 +162,18 @@ type SpeedLimitReq struct {
|
||||
Extend string `json:"extend,omitempty" description:"扩展字段(广电国网特殊参数)"`
|
||||
}
|
||||
|
||||
// WiFiParams 是设置设备 WiFi 的内层参数
|
||||
type WiFiParams struct {
|
||||
SSIDName string `json:"ssidName" validate:"required,min=1,max=32" required:"true" minLength:"1" maxLength:"32" description:"WiFi 名称"`
|
||||
SSIDPassword string `json:"ssidPassword,omitempty" description:"WiFi 密码"`
|
||||
}
|
||||
|
||||
// WiFiReq 是设置设备 WiFi 的请求
|
||||
// Gateway 实际要求的结构为 {"params":{"cardNo":"设备IMEI","params":{"ssidName":"...","ssidPassword":"..."}}}
|
||||
type WiFiReq struct {
|
||||
CardNo string `json:"cardNo" validate:"required" required:"true" description:"流量卡号(ICCID)"`
|
||||
DeviceID string `json:"deviceId,omitempty" description:"设备 ID/IMEI"`
|
||||
SSID string `json:"ssid" validate:"required,min=1,max=32" required:"true" minLength:"1" maxLength:"32" description:"WiFi 名称"`
|
||||
Password string `json:"password,omitempty" description:"WiFi 密码"`
|
||||
Enabled bool `json:"enabled" description:"启用状态"`
|
||||
Extend string `json:"extend,omitempty" description:"扩展字段(广电国网特殊参数)"`
|
||||
CardNo string `json:"cardNo" validate:"required" required:"true" description:"设备 IMEI"`
|
||||
Params WiFiParams `json:"params" required:"true" description:"WiFi 配置参数"`
|
||||
Extend string `json:"extend,omitempty" description:"扩展字段(广电国网特殊参数)"`
|
||||
}
|
||||
|
||||
// SwitchCardReq 是设备切换卡的请求
|
||||
|
||||
@@ -254,11 +254,11 @@ func (h *ClientDeviceHandler) SetWiFi(c *fiber.Ctx) error {
|
||||
// 调用 Gateway 配置 WiFi
|
||||
// CardNo 字段虽名为"卡号",但 Gateway 实际要求传入设备 IMEI
|
||||
if err := h.gatewayClient.SetWiFi(c.UserContext(), &gateway.WiFiReq{
|
||||
CardNo: info.IMEI,
|
||||
DeviceID: info.IMEI,
|
||||
SSID: req.SSID,
|
||||
Password: req.Password,
|
||||
Enabled: req.Enabled,
|
||||
CardNo: info.IMEI,
|
||||
Params: gateway.WiFiParams{
|
||||
SSIDName: req.SSID,
|
||||
SSIDPassword: req.Password,
|
||||
},
|
||||
}); err != nil {
|
||||
h.logger.Error("Gateway配置WiFi失败",
|
||||
zap.String("imei", info.IMEI),
|
||||
|
||||
@@ -169,7 +169,6 @@ type SetSpeedLimitRequest struct {
|
||||
// SetWiFiRequest 设置设备 WiFi 请求
|
||||
type SetWiFiRequest struct {
|
||||
Identifier string `path:"identifier" description:"设备标识符(支持虚拟号/IMEI/SN)" required:"true"`
|
||||
CardNo string `json:"card_no" validate:"required" required:"true" description:"流量卡号(ICCID)"`
|
||||
SSID string `json:"ssid" validate:"required,min=1,max=32" required:"true" minLength:"1" maxLength:"32" description:"WiFi 名称"`
|
||||
Password string `json:"password,omitempty" description:"WiFi 密码"`
|
||||
Enabled bool `json:"enabled" description:"启用状态"`
|
||||
|
||||
@@ -290,7 +290,7 @@ func getOperationFieldDesc(operationType string) map[string]string {
|
||||
}
|
||||
case "device_set_wifi":
|
||||
return map[string]string{
|
||||
"card_no": "卡槽/卡序号",
|
||||
"imei": "设备 IMEI",
|
||||
"ssid": "WiFi 名称",
|
||||
"password": "WiFi 密码(脱敏)",
|
||||
"enabled": "WiFi 开关状态",
|
||||
|
||||
@@ -116,7 +116,6 @@ func (s *Service) GatewaySetWiFi(ctx context.Context, identifier string, req *dt
|
||||
nil,
|
||||
map[string]any{
|
||||
"identifier": identifier,
|
||||
"card_no": req.CardNo,
|
||||
"ssid": req.SSID,
|
||||
"enabled": req.Enabled,
|
||||
"password": req.Password,
|
||||
@@ -129,11 +128,11 @@ func (s *Service) GatewaySetWiFi(ctx context.Context, identifier string, req *dt
|
||||
return err
|
||||
}
|
||||
if err = s.gatewayClient.SetWiFi(ctx, &gateway.WiFiReq{
|
||||
CardNo: req.CardNo,
|
||||
DeviceID: imei,
|
||||
SSID: req.SSID,
|
||||
Password: req.Password,
|
||||
Enabled: req.Enabled,
|
||||
CardNo: imei,
|
||||
Params: gateway.WiFiParams{
|
||||
SSIDName: req.SSID,
|
||||
SSIDPassword: req.Password,
|
||||
},
|
||||
}); err != nil {
|
||||
s.logDeviceOperation(
|
||||
ctx,
|
||||
@@ -143,7 +142,7 @@ func (s *Service) GatewaySetWiFi(ctx context.Context, identifier string, req *dt
|
||||
device,
|
||||
map[string]any{"device": deviceSnapshot(device)},
|
||||
map[string]any{
|
||||
"card_no": req.CardNo,
|
||||
"imei": imei,
|
||||
"ssid": req.SSID,
|
||||
"enabled": req.Enabled,
|
||||
"password": req.Password,
|
||||
@@ -164,7 +163,7 @@ func (s *Service) GatewaySetWiFi(ctx context.Context, identifier string, req *dt
|
||||
device,
|
||||
map[string]any{"device": deviceSnapshot(device)},
|
||||
map[string]any{
|
||||
"card_no": req.CardNo,
|
||||
"imei": imei,
|
||||
"ssid": req.SSID,
|
||||
"enabled": req.Enabled,
|
||||
"password": req.Password,
|
||||
|
||||
Reference in New Issue
Block a user