|
@@ -4,10 +4,10 @@ import cn.hutool.extra.spring.SpringUtil;
|
|
|
import com.fjhx.iot.entity.tda.po.TdaConfig;
|
|
|
import com.fjhx.iot.service.tda.TdaConfigService;
|
|
|
import com.huaweicloud.sdk.core.auth.ICredential;
|
|
|
+import com.huaweicloud.sdk.core.region.Region;
|
|
|
import com.huaweicloud.sdk.iotda.v5.IoTDAClient;
|
|
|
import com.huaweicloud.sdk.iotda.v5.auth.IoTDACredentials;
|
|
|
import com.huaweicloud.sdk.iotda.v5.model.*;
|
|
|
-import com.huaweicloud.sdk.iotda.v5.region.IoTDARegion;
|
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
|
import lombok.Data;
|
|
|
|
|
@@ -15,7 +15,12 @@ import java.util.Collections;
|
|
|
|
|
|
public class IoTDAUtil {
|
|
|
|
|
|
- private static TdaConfigService tdaConfigService = SpringUtil.getBean(TdaConfigService.class);
|
|
|
+ // REGION_ID:如果是上海一,请填写"cn-east-3";如果是北京四,请填写"cn-north-4";如果是华南广州,请填写"cn-south-4"
|
|
|
+ private static final String REGION_ID = "ap-southeast-1";
|
|
|
+ // ENDPOINT:请在控制台的"总览"界面的"平台接入地址"中查看“应用侧”的https接入地址。
|
|
|
+ private static final String ENDPOINT = "a0ba517e07.st1.iotda-app.ap-southeast-1.myhuaweicloud.com";
|
|
|
+
|
|
|
+ private static final TdaConfigService tdaConfigService = SpringUtil.getBean(TdaConfigService.class);
|
|
|
|
|
|
/**
|
|
|
* 创建资源空间
|
|
@@ -136,13 +141,20 @@ public class IoTDAUtil {
|
|
|
* @param productId 产品id
|
|
|
* @return 设备secret
|
|
|
*/
|
|
|
- public static DeviceKey addDevice(Long configId, String nodeId, String deviceName, String appId, String productId) {
|
|
|
+ public static DeviceKey addDevice(Long configId, String nodeId, String deviceName,
|
|
|
+ String appId, String productId, String secret) {
|
|
|
+
|
|
|
+ AuthInfo authInfo = new AuthInfo();
|
|
|
+ authInfo.setSecret(secret);
|
|
|
+
|
|
|
AddDeviceRequest addDeviceRequest = new AddDeviceRequest();
|
|
|
AddDevice addDevice = new AddDevice();
|
|
|
addDevice.setNodeId(nodeId);
|
|
|
addDevice.setDeviceName(deviceName);
|
|
|
addDevice.setAppId(appId);
|
|
|
addDevice.setProductId(productId);
|
|
|
+ addDevice.setAuthInfo(authInfo);
|
|
|
+ addDevice.setDeviceId(nodeId);
|
|
|
|
|
|
addDeviceRequest.setBody(addDevice);
|
|
|
AddDeviceResponse addDeviceResponse = getIoTDAClient(configId).addDevice(addDeviceRequest);
|
|
@@ -195,9 +207,9 @@ public class IoTDAUtil {
|
|
|
return IoTDAClient.newBuilder()
|
|
|
.withCredential(auth)
|
|
|
// 基础版:请选择IoTDARegion中的Region对象
|
|
|
- .withRegion(IoTDARegion.CN_NORTH_4)
|
|
|
+ // .withRegion(IoTDARegion.CN_NORTH_4)
|
|
|
// 标准版/企业版:需自行创建Region对象
|
|
|
- // .withRegion(new Region(REGION_ID, ENDPOINT))
|
|
|
+ .withRegion(new Region(REGION_ID, ENDPOINT))
|
|
|
.build();
|
|
|
}
|
|
|
|