feat:【IoT 物联网】优化获取认证信息的逻辑
This commit is contained in:
parent
7b114e1986
commit
72245b5b0d
|
@ -167,12 +167,11 @@ public class IotDeviceController {
|
||||||
return success(true);
|
return success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO @haohao:是不是默认详情接口,不返回 secret,然后这个接口,用于统一返回。然后接口名可以更通用一点。
|
@GetMapping("/get-auth-info")
|
||||||
@GetMapping("/mqtt-connection-params")
|
@Operation(summary = "获得设备连接信息")
|
||||||
@Operation(summary = "获取 MQTT 连接参数")
|
@PreAuthorize("@ss.hasPermission('iot:device:auth-info')")
|
||||||
@PreAuthorize("@ss.hasPermission('iot:device:mqtt-connection-params')")
|
public CommonResult<IotDeviceAuthInfoRespVO> getDeviceAuthInfo(@RequestParam("id") Long id) {
|
||||||
public CommonResult<IotDeviceMqttConnectionParamsRespVO> getMqttConnectionParams(@RequestParam("deviceId") Long deviceId) {
|
return success(deviceService.getDeviceAuthInfo(id));
|
||||||
return success(deviceService.getMqttConnectionParams(deviceId));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO @haohao:可以使用 @RequestParam("productKey") String productKey, @RequestParam("deviceNames") List<String> deviceNames 来接收哇?
|
// TODO @haohao:可以使用 @RequestParam("productKey") String productKey, @RequestParam("deviceNames") List<String> deviceNames 来接收哇?
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
package cn.iocoder.yudao.module.iot.controller.admin.device.vo.device;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Schema(description = "管理后台 - IoT 设备认证信息 Response VO")
|
||||||
|
@Data
|
||||||
|
public class IotDeviceAuthInfoRespVO {
|
||||||
|
|
||||||
|
@Schema(description = "客户端 ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "product123.device001")
|
||||||
|
@NotBlank(message = "客户端 ID 不能为空")
|
||||||
|
private String clientId;
|
||||||
|
|
||||||
|
@Schema(description = "用户名", requiredMode = Schema.RequiredMode.REQUIRED, example = "device001&product123")
|
||||||
|
@NotBlank(message = "用户名不能为空")
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
@Schema(description = "密码", requiredMode = Schema.RequiredMode.REQUIRED, example = "1a2b3c4d5e6f7890abcdef1234567890")
|
||||||
|
@NotBlank(message = "密码不能为空")
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
}
|
|
@ -1,25 +0,0 @@
|
||||||
package cn.iocoder.yudao.module.iot.controller.admin.device.vo.device;
|
|
||||||
|
|
||||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
|
||||||
import com.alibaba.excel.annotation.ExcelProperty;
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Schema(description = "管理后台 - IoT 设备 MQTT 连接参数 Response VO")
|
|
||||||
@Data
|
|
||||||
@ExcelIgnoreUnannotated
|
|
||||||
public class IotDeviceMqttConnectionParamsRespVO {
|
|
||||||
|
|
||||||
@Schema(description = "MQTT 客户端 ID", example = "24602")
|
|
||||||
@ExcelProperty("MQTT 客户端 ID")
|
|
||||||
private String mqttClientId;
|
|
||||||
|
|
||||||
@Schema(description = "MQTT 用户名", example = "芋艿")
|
|
||||||
@ExcelProperty("MQTT 用户名")
|
|
||||||
private String mqttUsername;
|
|
||||||
|
|
||||||
@Schema(description = "MQTT 密码")
|
|
||||||
@ExcelProperty("MQTT 密码")
|
|
||||||
private String mqttPassword;
|
|
||||||
|
|
||||||
}
|
|
|
@ -216,12 +216,12 @@ public interface IotDeviceService {
|
||||||
Long getDeviceCount(@Nullable LocalDateTime createTime);
|
Long getDeviceCount(@Nullable LocalDateTime createTime);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取 MQTT 连接参数
|
* 获得设备认证信息
|
||||||
*
|
*
|
||||||
* @param deviceId 设备 ID
|
* @param id 设备编号
|
||||||
* @return MQTT 连接参数
|
* @return MQTT 连接参数
|
||||||
*/
|
*/
|
||||||
IotDeviceMqttConnectionParamsRespVO getMqttConnectionParams(Long deviceId);
|
IotDeviceAuthInfoRespVO getDeviceAuthInfo(Long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得各个产品下的设备数量 Map
|
* 获得各个产品下的设备数量 Map
|
||||||
|
|
|
@ -409,17 +409,13 @@ public class IotDeviceServiceImpl implements IotDeviceService {
|
||||||
return respVO;
|
return respVO;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO @芋艿:改成通用的;
|
|
||||||
@Override
|
@Override
|
||||||
public IotDeviceMqttConnectionParamsRespVO getMqttConnectionParams(Long deviceId) {
|
public IotDeviceAuthInfoRespVO getDeviceAuthInfo(Long id) {
|
||||||
IotDeviceDO device = validateDeviceExists(deviceId);
|
IotDeviceDO device = validateDeviceExists(id);
|
||||||
// MqttSignResult mqttSignResult = MqttSignUtils.calculate(device.getProductKey(), device.getDeviceName(),
|
// 使用 IotDeviceAuthUtils 生成认证信息
|
||||||
// device.getDeviceSecret());
|
IotDeviceAuthUtils.AuthInfo authInfo = IotDeviceAuthUtils.getAuthInfo(
|
||||||
// return new IotDeviceMqttConnectionParamsRespVO()
|
device.getProductKey(), device.getDeviceName(), device.getDeviceSecret());
|
||||||
// .setMqttClientId(mqttSignResult.getClientId())
|
return BeanUtils.toBean(authInfo, IotDeviceAuthInfoRespVO.class);
|
||||||
// .setMqttUsername(mqttSignResult.getUsername())
|
|
||||||
// .setMqttPassword(mqttSignResult.getPassword());
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteDeviceCache(IotDeviceDO device) {
|
private void deleteDeviceCache(IotDeviceDO device) {
|
||||||
|
|
Loading…
Reference in New Issue