diff --git a/yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/codec/tcp/IotTcpJsonDeviceMessageCodec.java b/yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/codec/tcp/IotTcpJsonDeviceMessageCodec.java index 368130d98c..10ffbdf5c6 100644 --- a/yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/codec/tcp/IotTcpJsonDeviceMessageCodec.java +++ b/yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/codec/tcp/IotTcpJsonDeviceMessageCodec.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.iot.gateway.codec.tcp; import cn.hutool.core.lang.Assert; +import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage; import cn.iocoder.yudao.module.iot.gateway.codec.IotDeviceMessageCodec; @@ -9,8 +10,6 @@ import lombok.Data; import lombok.NoArgsConstructor; import org.springframework.stereotype.Component; -import java.nio.charset.StandardCharsets; - /** * TCP JSON 格式 {@link IotDeviceMessage} 编解码器 * @@ -95,7 +94,7 @@ public class IotTcpJsonDeviceMessageCodec implements IotDeviceMessageCodec { @Override @SuppressWarnings("DataFlowIssue") public IotDeviceMessage decode(byte[] bytes) { - String jsonStr = new String(bytes, StandardCharsets.UTF_8).trim(); + String jsonStr = StrUtil.utf8Str(bytes).trim(); TcpJsonMessage tcpJsonMessage = JsonUtils.parseObject(jsonStr, TcpJsonMessage.class); Assert.notNull(tcpJsonMessage, "消息不能为空"); Assert.notBlank(tcpJsonMessage.getMethod(), "消息方法不能为空"); diff --git a/yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/tcp/router/IotTcpUpstreamHandler.java b/yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/tcp/router/IotTcpUpstreamHandler.java index 1659890189..0aff8f72f2 100644 --- a/yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/tcp/router/IotTcpUpstreamHandler.java +++ b/yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/tcp/router/IotTcpUpstreamHandler.java @@ -364,6 +364,7 @@ public class IotTcpUpstreamHandler implements Handler { * @param message 消息 * @param codecType 消息编解码类型 */ + @SuppressWarnings("SameParameterValue") private void sendSuccessResponse(NetSocket socket, String requestId, String message, String codecType) { sendResponse(socket, true, message, requestId, codecType); } @@ -374,6 +375,7 @@ public class IotTcpUpstreamHandler implements Handler { * @param params 参数对象(通常为 Map 类型) * @return 认证参数 DTO,解析失败时返回 null */ + @SuppressWarnings("unchecked") private IotDeviceAuthReqDTO parseAuthParams(Object params) { if (params == null) { return null; @@ -382,7 +384,6 @@ public class IotTcpUpstreamHandler implements Handler { try { // 参数默认为 Map 类型,直接转换 if (params instanceof java.util.Map) { - @SuppressWarnings("unchecked") java.util.Map paramMap = (java.util.Map) params; return new IotDeviceAuthReqDTO() .setClientId(MapUtil.getStr(paramMap, "clientId")) @@ -398,9 +399,8 @@ public class IotTcpUpstreamHandler implements Handler { // 其他情况尝试 JSON 转换 String jsonStr = JsonUtils.toJsonString(params); return JsonUtils.parseObject(jsonStr, IotDeviceAuthReqDTO.class); - } catch (Exception e) { - log.error("[parseAuthParams][解析认证参数失败]", e); + log.error("[parseAuthParams][解析认证参数({})失败]", params, e); return null; } }