Pārlūkot izejas kodu

update:修改productkey

荭琪枫 1 gadu atpakaļ
vecāks
revīzija
b5d60b6611

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
data/components/6c095554-35e7-4e9d-a8d2-bb919e9479f4/component.js


+ 4 - 1
data/components/eabb131d-8fd1-43a8-88d9-a198abfd3d42/component.js

@@ -122,10 +122,13 @@ function register(payload) {
     var pk = arr[0];
     var dn = arr[1];
     var model = arr[2];
-    var pwd = md5("xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU" + auth.clientid);
+    var product = deviceBehaviour.getProductKey(pk)
+    var pwd = md5(product.productSecret + auth.clientid);
+
     if (pwd.toLocaleLowerCase() != auth.password.toLocaleLowerCase()) {
         throw new Error("incorrect password");
     }
+
     return {
         type: "register",
         data: {

+ 16 - 0
data/init/product.json

@@ -1,6 +1,7 @@
 [
   {
     "productKey": "xpsYHExTKPFaQMS7",
+    "productSecret": "xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU",
     "name": "调光灯",
     "category": "light",
     "nodeType": 1,
@@ -11,6 +12,7 @@
   },
   {
     "productKey": "hdX3PCMcFrCYpesJ",
+    "productSecret": "xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU",
     "code": "hdX3PCMcFrCYpesJ",
     "name": "智能风扇",
     "category": "fan",
@@ -21,6 +23,7 @@
   },
   {
     "productKey": "hbtgIA0SuVw9lxjB",
+    "productSecret": "xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU",
     "name": "GW01网关",
     "category": "gateway",
     "nodeType": 0,
@@ -32,6 +35,7 @@
   },
   {
     "productKey": "eDhXKwEzwFybM5R7",
+    "productSecret": "xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU",
     "name": "三路开关",
     "category": "switch",
     "nodeType": 1,
@@ -43,6 +47,7 @@
   },
   {
     "productKey": "cGCrkK7Ex4FESAwe",
+    "productSecret": "xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU",
     "name": "插座",
     "category": "SmartPlug",
     "nodeType": 1,
@@ -54,6 +59,7 @@
   },
   {
     "productKey": "Rf4QSjbm65X45753",
+    "productSecret": "xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU",
     "name": "一路开关",
     "category": "switch",
     "nodeType": 1,
@@ -65,6 +71,7 @@
   },
   {
     "productKey": "PN3EDmkBZDD8whDd",
+    "productSecret": "xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU",
     "name": "门磁",
     "category": "door",
     "nodeType": 1,
@@ -75,6 +82,7 @@
   },
   {
     "productKey": "N523nWsCiG3CAn6X",
+    "productSecret": "xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU",
     "name": "ZGW01",
     "category": "gateway",
     "nodeType": 0,
@@ -86,6 +94,7 @@
   },
   {
     "productKey": "Eit3kmGJtxSHfCKT",
+    "productSecret": "xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU",
     "name": "燃气表",
     "category": "meter",
     "nodeType": 2,
@@ -96,6 +105,7 @@
   },
   {
     "productKey": "DSGxxKk6E8mmDk6C",
+    "productSecret": "xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU",
     "name": "通断器",
     "category": "switch",
     "nodeType": 1,
@@ -107,6 +117,7 @@
   },
   {
     "productKey": "D8c5pXFmt2KJDxNm",
+    "productSecret": "xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU",
     "name": "四路场景面板",
     "category": "switch",
     "nodeType": 1,
@@ -116,6 +127,7 @@
   },
   {
     "productKey": "AWcJnf7ymGSkaz5M",
+    "productSecret": "xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU",
     "name": "smart pulg",
     "category": "SmartPlug",
     "nodeType": 1,
@@ -127,6 +139,7 @@
   },
   {
     "productKey": "6kYp6jszrDns2yh4",
+    "productSecret": "xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU",
     "name": "温湿度传感器",
     "category": "sensor",
     "nodeType": 1,
@@ -136,6 +149,7 @@
   },
   {
     "productKey": "bGdZt8ffBETtsirm",
+    "productSecret": "xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU",
     "name": "新风",
     "category": "FreshAir",
     "nodeType": 1,
@@ -145,6 +159,7 @@
   },
   {
     "productKey": "BRD3x4fkKxkaxXFt",
+    "productSecret": "xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU",
     "name": "智能电表采集器",
     "category": "gateway",
     "nodeType": 0,
@@ -154,6 +169,7 @@
   },
   {
     "productKey": "PwMfpXmp4ZWkGahn",
+    "productSecret": "xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU",
     "name": "智能电表",
     "category": "SmartMeter",
     "nodeType": 1,

+ 0 - 3
iot-common/iot-common-core/src/main/java/cc/iotkit/common/constant/Constants.java

@@ -77,9 +77,6 @@ public interface Constants {
      */
     Long TOP_PARENT_ID = 0L;
 
-
-    String PRODUCT_SECRET = "xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU";
-
     String ACCOUNT_SECRET = "3n1z33kzvpgz1foijpkepyd3e8tw84us";
 
     String CACHE_PRODUCT = "product_cache";

+ 9 - 4
iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/DeviceBehaviourService.java

@@ -165,7 +165,8 @@ public class DeviceBehaviourService {
         if (deviceInfo == null) {
             throw new BizException(ErrCode.DEVICE_NOT_FOUND);
         }
-        if (!Constants.PRODUCT_SECRET.equals(productSecret)) {
+        Product product = getProductKey(productKey);
+        if (!product.getProductSecret().equals(productSecret)) {
             throw new BizException(ErrCode.PRODUCT_SECRET_ERROR);
         }
 
@@ -284,14 +285,18 @@ public class DeviceBehaviourService {
         deviceOtaInfoTemp.setProductKey(message.getProductKey());
         DeviceOtaInfo deviceOtaInfo = deviceOtaInfoData.findOneByCondition(DeviceOtaInfo.builder()
                 .taskId(message.getMid())
-                        .productKey(message.getProductKey())
-                        .deviceName(message.getDeviceName())
+                .productKey(message.getProductKey())
+                .deviceName(message.getDeviceName())
                 .deviceId(message.getDeviceId()).build());
         if (Objects.nonNull(deviceOtaInfo)) {
             deviceOtaInfo.setStep(deviceOtaInfoTemp.getStep());
-        }else{
+        } else {
             deviceOtaInfo = deviceOtaInfoTemp;
         }
         deviceOtaInfoData.save(deviceOtaInfo);
     }
+
+    public Product getProductKey(String productKey) {
+        return productData.findByProductKey(productKey);
+    }
 }

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
iot-components/iot-emqx-component/src/main/resources/component.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
iot-components/iot-mqtt-component/src/main/resources/ali-component.js


+ 4 - 1
iot-components/iot-mqtt-component/src/main/resources/component.js

@@ -122,7 +122,10 @@ function register(payload) {
     var pk = arr[0];
     var dn = arr[1];
     var model = arr[2];
-    var pwd = md5("xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU" + auth.clientid);
+
+    var product = deviceBehaviour.getProductKey(pk)
+    var pwd = md5(product.productSecret + auth.clientid);
+
     if (pwd.toLocaleLowerCase() != auth.password.toLocaleLowerCase()) {
         throw new Error("incorrect password");
     }

+ 3 - 3
iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/example/TransparentTest.java

@@ -41,10 +41,10 @@ public class TransparentTest {
         }
 
         log.info("start gateway ");
-        Gateway gateway = new Gateway("hbtgIA0SuVw9lxjB",
+        Gateway gateway = new Gateway("hbtgIA0SuVw9lxjB", "xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU",
                 "TEST:GW:T0001");
 
-        gateway.addSubDevice("",
+        gateway.addSubDevice("hbtgIA0SuVw9lxjB", "xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU",
                 "TEST_LIGHT_0001",
                 "M1");
 
@@ -54,7 +54,7 @@ public class TransparentTest {
             //设备上线后添加上报定时任务
             ReportTask reportTask = new ReportTask(gateway.getClient());
             reportTask.addTask(String.format("/sys/%s/%s/s/event/rawReport",
-                    pk, device.getDeviceName()),
+                            pk, device.getDeviceName()),
                     () -> {
                         Request request = new Request();
                         request.setId(UUID.randomUUID().toString());

+ 1 - 1
iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/performance/ConnectionTest.java

@@ -43,7 +43,7 @@ public class ConnectionTest {
             int finalI = i;
             executor.submit(() -> {
                 log.info("start gateway " + (finalI + 1));
-                Gateway gateway = new Gateway("hbtgIA0SuVw9lxjB",
+                Gateway gateway = new Gateway("hbtgIA0SuVw9lxjB","xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU",
                         "TEST:GW:T" + StringUtils.leftPad(finalI + "", 6, "0"));
 
 //                gateway.addSubDevice("Rf4QSjbm65X45753",

+ 4 - 4
iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/performance/ReportTest.java

@@ -51,14 +51,14 @@ public class ReportTest {
             int finalI = i;
             executor.submit(() -> {
                 log.info("start gateway " + (finalI + 1));
-                Gateway gateway = new Gateway("hbtgIA0SuVw9lxjB",
+                Gateway gateway = new Gateway("hbtgIA0SuVw9lxjB", "xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU",
                         "TEST:GW:" + StringUtils.leftPad(finalI + "", 6, "0"));
 
-                gateway.addSubDevice("Rf4QSjbm65X45753",
+                gateway.addSubDevice("Rf4QSjbm65X45753", "xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU",
                         "TEST_SW_" + StringUtils.leftPad(finalI + "", 6, "0"),
                         "S01");
 
-                gateway.addSubDevice("cGCrkK7Ex4FESAwe",
+                gateway.addSubDevice("cGCrkK7Ex4FESAwe", "xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU",
                         "TEST_SC_" + StringUtils.leftPad(finalI + "", 6, "0"),
                         "S01");
 
@@ -71,7 +71,7 @@ public class ReportTest {
                     //设备上线后添加上报定时任务
                     ReportTask reportTask = new ReportTask(gateway.getClient());
                     reportTask.addTask(String.format("/sys/%s/%s/s/event/property/post",
-                            pk, device.getDeviceName()),
+                                    pk, device.getDeviceName()),
                             () -> {
                                 Request request = new Request();
                                 request.setId(UUID.randomUUID().toString());

+ 2 - 0
iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/service/Device.java

@@ -20,6 +20,8 @@ public class Device {
 
     protected String productKey;
 
+    private String productSecret ;
+
     protected String deviceName;
 
     private String model;

+ 5 - 5
iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/service/Gateway.java

@@ -49,8 +49,8 @@ public class Gateway extends Device {
 
     private boolean isConnecting;
 
-    public Gateway(String productKey, String deviceName) {
-        super(productKey, deviceName, "GW01");
+    public Gateway(String productKey, String productSecret, String deviceName) {
+        super(productKey, productSecret, deviceName, "GW01");
     }
 
     @SneakyThrows
@@ -74,7 +74,7 @@ public class Gateway extends Device {
             isConnecting = true;
             MqttClientOptions options = new MqttClientOptions();
             options.setUsername(this.deviceName);
-            options.setPassword(DigestUtils.md5Hex(Constants.PRODUCT_SECRET + clientId));
+            options.setPassword(DigestUtils.md5Hex(getProductSecret() + clientId));
             options.setCleanSession(true);
             options.setKeepAliveInterval(30);
             options.setClientId(clientId);
@@ -134,8 +134,8 @@ public class Gateway extends Device {
         }
     }
 
-    public void addSubDevice(String productKey, String deviceName, String model) {
-        subDevices.add(new Device(productKey, deviceName, model));
+    public void addSubDevice(String productKey, String productSecret, String deviceName, String model) {
+        subDevices.add(new Device(productKey, productSecret, deviceName, model));
     }
 
     public void onDeviceOnline(Consumer<Device> listener) {

Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels