Browse Source

修改传感器设备时间戳token校验方式

locky 3 năm trước cách đây
mục cha
commit
3c69ec9192
2 tập tin đã thay đổi với 21 bổ sung1 xóa
  1. 1 1
      SensorGateway/SensorGatewayController.py
  2. 20 0
      Service/CommonService.py

+ 1 - 1
SensorGateway/SensorGatewayController.py

@@ -51,7 +51,7 @@ class SensorGateway(View):
             return response.json(444, {'param': 'time_stamp, time_stamp_token'})
         try:
             # 时间戳token校验
-            if not CommonService.check_time_stamp_token(time_stamp_token, time_stamp):
+            if not CommonService.check_time_stamp_token_without_distance(time_stamp, time_stamp_token):
                 return response.json(13)
 
             sensor_id = ''.join(random.sample(string.ascii_letters + string.digits, 6))

+ 20 - 0
Service/CommonService.py

@@ -454,6 +454,26 @@ class CommonService:
             print(e)
             return False
 
+    @staticmethod
+    def check_time_stamp_token_without_distance(time_stamp, time_stamp_token):
+        """
+        用于没有RTC设备的时间戳token校验
+        @param time_stamp: 时间戳
+        @param time_stamp_token: 时间戳token
+        @return: boolean True/False
+        """
+
+        if not all([time_stamp, time_stamp_token]):
+            return False
+        try:
+            token = CommonService.decode_data(time_stamp_token)
+            if token != time_stamp:
+                return False
+            return True
+        except Exception as e:
+            print(e)
+            return False
+
     @staticmethod
     def req_publish_mqtt_msg(thing_name, topic_name, msg):
         # 通用发布MQTT消息函数