Procházet zdrojové kódy

设备获取证书

chenshibin před 4 roky
rodič
revize
d1fe00e624
2 změnil soubory, kde provedl 22 přidání a 9 odebrání
  1. 2 1
      Controller/IotCoreController.py
  2. 20 8
      Object/IOTCore/IotObject.py

+ 2 - 1
Controller/IotCoreController.py

@@ -86,6 +86,7 @@ class IotCoreView(View):
         uid_code = request_dict.get('uid_code', None)
         token = request_dict.get('token', None)
         time_stamp = request_dict.get('time_stamp', None)
+        device_version = request_dict.get('device_version', None)
 
         if uid and token and time_stamp and uid_code:
             uid_code = CommonService.decode_data(uid_code)
@@ -123,7 +124,7 @@ class IotCoreView(View):
 
                     else:
                         iotClient = AmericaIOTClient()
-                    res = iotClient.create_keys_and_certificate(uid)
+                    res = iotClient.create_keys_and_certificate(uid, device_version)
                     nowTime = int(time.time())
                     token_iot_number = hashlib.md5((str(uuid.uuid1()) + str(nowTime)).encode('utf-8')).hexdigest()
                     Device_Info.objects.filter(UID=uid).update(endpoint=res[0]['endpoint'], token_iot_number=token_iot_number )

+ 20 - 8
Object/IOTCore/IotObject.py

@@ -41,7 +41,7 @@ class ChinaIOTClient(IOTObject):
         }
         return res
 
-    def create_keys_and_certificate(self, uid):
+    def create_keys_and_certificate(self, uid, device_version):
         result = self.client.create_keys_and_certificate(setAsActive=True)
         res = {
             'certificateId': result['certificateId'],
@@ -71,7 +71,9 @@ class ChinaIOTClient(IOTObject):
                     "Type": "AWS::IoT::Thing",
                     "Properties": {
                         "AttributePayload": {},
-                        "ThingGroups": [],
+                        "ThingGroups": {
+                            "Ref": "ThingGroups"
+                        },
                         "ThingName": {
                             "Ref": "ThingName"
                         },
@@ -100,6 +102,7 @@ class ChinaIOTClient(IOTObject):
 
         templateBody = json.dumps(templateBody)
         parameters = {"ThingName": "Ansjer_Device_" + uid,
+                      "ThingGroups": device_version,
                       "AWS::IoT::Certificate::Id": res['certificateId']}
         self.client.register_thing(
             templateBody=templateBody,
@@ -128,7 +131,7 @@ class AmericaIOTClient(IOTObject):
         }
         return res
 
-    def create_keys_and_certificate(self, uid):
+    def create_keys_and_certificate(self, uid, device_version):
         result = self.client.create_keys_and_certificate(setAsActive=True)
         res = {
             'certificateId': result['certificateId'],
@@ -158,7 +161,9 @@ class AmericaIOTClient(IOTObject):
                     "Type": "AWS::IoT::Thing",
                     "Properties": {
                         "AttributePayload": {},
-                        "ThingGroups": [],
+                        "ThingGroups": {
+                            "Ref": "ThingGroups"
+                        },
                         "ThingName": {
                             "Ref": "ThingName"
                         },
@@ -187,6 +192,7 @@ class AmericaIOTClient(IOTObject):
 
         templateBody = json.dumps(templateBody)
         parameters = {"ThingName": "Ansjer_Device_" + uid,
+                      "ThingGroups": device_version,
                       "AWS::IoT::Certificate::Id": res['certificateId']}
         self.client.register_thing(
             templateBody=templateBody,
@@ -214,7 +220,7 @@ class AsiaIOTClient(IOTObject):
         }
         return res
 
-    def create_keys_and_certificate(self, uid):
+    def create_keys_and_certificate(self, uid, device_version):
         result = self.client.create_keys_and_certificate(setAsActive=True)
         res = {
             'certificateId': result['certificateId'],
@@ -244,7 +250,9 @@ class AsiaIOTClient(IOTObject):
                     "Type": "AWS::IoT::Thing",
                     "Properties": {
                         "AttributePayload": {},
-                        "ThingGroups": [],
+                        "ThingGroups": {
+                            "Ref": "ThingGroups"
+                        },
                         "ThingName": {
                             "Ref": "ThingName"
                         },
@@ -273,6 +281,7 @@ class AsiaIOTClient(IOTObject):
 
         templateBody = json.dumps(templateBody)
         parameters = {"ThingName": "Ansjer_Device_" + uid,
+                      "ThingGroups": device_version,
                       "AWS::IoT::Certificate::Id": res['certificateId']}
         self.client.register_thing(
             templateBody=templateBody,
@@ -300,7 +309,7 @@ class EuropeIOTClient(IOTObject):
         }
         return res
 
-    def create_keys_and_certificate(self, uid):
+    def create_keys_and_certificate(self, uid, device_version):
         result = self.client.create_keys_and_certificate(setAsActive=True)
         res = {
             'certificateId': result['certificateId'],
@@ -330,7 +339,9 @@ class EuropeIOTClient(IOTObject):
                     "Type": "AWS::IoT::Thing",
                     "Properties": {
                         "AttributePayload": {},
-                        "ThingGroups": [],
+                        "ThingGroups": {
+                            "Ref": "ThingGroups"
+                        },
                         "ThingName": {
                             "Ref": "ThingName"
                         },
@@ -359,6 +370,7 @@ class EuropeIOTClient(IOTObject):
 
         templateBody = json.dumps(templateBody)
         parameters = {"ThingName": "Ansjer_Device_" + uid,
+                      "ThingGroups": device_version,
                       "AWS::IoT::Certificate::Id": res['certificateId']}
         self.client.register_thing(
             templateBody=templateBody,