From 638976dac81a7098b0e8d563379a05e7fd4d6c8b Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 16 Mar 2025 23:15:32 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BB=A3=E7=A0=81=E8=AF=84=E5=AE=A1?= =?UTF-8?q?=E3=80=91IoT=EF=BC=9A=E6=95=B4=E4=BD=93=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../control/IotDeviceUpstreamServiceImpl.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/control/IotDeviceUpstreamServiceImpl.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/control/IotDeviceUpstreamServiceImpl.java index 29e8096a95..6c80e75ace 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/control/IotDeviceUpstreamServiceImpl.java +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/control/IotDeviceUpstreamServiceImpl.java @@ -280,11 +280,11 @@ public class IotDeviceUpstreamServiceImpl implements IotDeviceUpstreamService { sendDeviceMessage(message, device); } + // TODO @芋艿:后续需要考虑,http 的认证 @Override public boolean authenticateEmqxConnection(IotDeviceEmqxAuthReqDTO authReqDTO) { log.info("[authenticateEmqxConnection][认证 Emqx 连接: {}]", authReqDTO); - // 1. 校验设备是否存在 - // username 格式:${DeviceName}&${ProductKey} + // 1.1 校验设备是否存在。username 格式:${DeviceName}&${ProductKey} String[] usernameParts = authReqDTO.getUsername().split("&"); if (usernameParts.length != 2) { log.error("[authenticateEmqxConnection][认证失败,username 格式不正确]"); @@ -292,17 +292,19 @@ public class IotDeviceUpstreamServiceImpl implements IotDeviceUpstreamService { } String deviceName = usernameParts[0]; String productKey = usernameParts[1]; - IotDeviceDO device = deviceService.getDeviceByProductKeyAndDeviceNameFromCache( - productKey, deviceName); + // 1.2 获得设备 + IotDeviceDO device = deviceService.getDeviceByProductKeyAndDeviceNameFromCache(productKey, deviceName); if (device == null) { - log.error("[authenticateEmqxConnection][设备({}/{}) 不存在]", - productKey, deviceName); + log.error("[authenticateEmqxConnection][设备({}/{}) 不存在]", productKey, deviceName); return false; } + // TODO @haohao:需要记录,记录设备的最后时间 + // 2. 校验密码 String deviceSecret = device.getDeviceSecret(); String clientId = authReqDTO.getClientId(); MqttSignResult sign = MqttSignUtils.calculate(productKey, deviceName, deviceSecret, clientId); + // TODO 建议,先失败,return false; if (StrUtil.equals(sign.getPassword(), authReqDTO.getPassword())) { log.info("[authenticateEmqxConnection][认证成功]"); return true;