Forráskód Böngészése

设备获取证书3

chenshibin 4 éve
szülő
commit
21b1b2da77
2 módosított fájl, 9 hozzáadás és 22 törlés
  1. 1 2
      Controller/IotCoreController.py
  2. 8 20
      Object/IOTCore/IotObject.py

+ 1 - 2
Controller/IotCoreController.py

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

+ 8 - 20
Object/IOTCore/IotObject.py

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