peng 2 lat temu
rodzic
commit
e117866a5d

+ 11 - 2
Controller/DetectControllerV2.py

@@ -53,6 +53,9 @@ class NotificationV2View(View):
         is_st = request_dict.get('is_st', None)
         is_st = request_dict.get('is_st', None)
         region = request_dict.get('region', None)
         region = request_dict.get('region', None)
         electricity = request_dict.get('electricity', '')
         electricity = request_dict.get('electricity', '')
+        time_token = request_dict.get('time_token', None)
+        time_stamp = request_dict.get('time_stamp', None)
+        uid = request_dict.get('uid', None)
 
 
         if not all([channel, n_time]):
         if not all([channel, n_time]):
             return JsonResponse(status=200, data={
             return JsonResponse(status=200, data={
@@ -60,12 +63,18 @@ class NotificationV2View(View):
                 'msg': 'param is wrong'})
                 'msg': 'param is wrong'})
         if not region or not is_st:
         if not region or not is_st:
             return JsonResponse(status=200, data={'code': 404, 'msg': 'no region or is_st'})
             return JsonResponse(status=200, data={'code': 404, 'msg': 'no region or is_st'})
-
+        # 时间戳token校验
+        if time_token and time_stamp:
+            time_stamp = int(time_stamp)
+            time_token = int(time_token)
+            if not CommonService.check_time_stamp_token(time_token, time_stamp):
+                return JsonResponse(status=200, data={'code': 13, 'msg': 'Timestamp token verification failed'})
         try:
         try:
             with transaction.atomic():
             with transaction.atomic():
                 is_st = int(is_st)
                 is_st = int(is_st)
                 region = int(region)
                 region = int(region)
-                uid = DevicePushService.decode_uid(etk, uidToken)  # 解密uid
+                if not uid:
+                    uid = DevicePushService.decode_uid(etk, uidToken)  # 解密uid
                 if len(uid) != 20 and len(uid) != 14:
                 if len(uid) != 20 and len(uid) != 14:
                     return JsonResponse(status=200, data={'code': 404, 'msg': 'wrong uid'})
                     return JsonResponse(status=200, data={'code': 404, 'msg': 'wrong uid'})
                 req_limiting = '{uid}_{channel}_{event_type}_ptl' \
                 req_limiting = '{uid}_{channel}_{event_type}_ptl' \

+ 36 - 1
Service/CommonService.py

@@ -1,4 +1,5 @@
 # -*- coding: utf-8 -*-
 # -*- coding: utf-8 -*-
+import base64
 import datetime
 import datetime
 import os
 import os
 import time
 import time
@@ -281,4 +282,38 @@ class CommonService:
         data = (''.join(dataList))
         data = (''.join(dataList))
         data = data + key
         data = data + key
         sign = hashlib.md5(data.encode(encoding="utf-8")).hexdigest()
         sign = hashlib.md5(data.encode(encoding="utf-8")).hexdigest()
-        return sign
+        return sign
+
+    @staticmethod
+    def check_time_stamp_token(token, time_stamp):
+        # 时间戳token校验
+        if not all([token, time_stamp]):
+            return False
+        try:
+            token = int(CommonService.decode_data(token))
+            time_stamp = int(time_stamp)
+            now_time = int(time.time())
+            distance = now_time - time_stamp
+            if token != time_stamp or distance > 60000 or distance < -60000:  # 为了全球化时间控制在一天内
+                return False
+            return True
+        except Exception as e:
+            print(e)
+            return False
+
+    @staticmethod
+    def decode_data(content, start=1, end=4):
+        """
+        数据解密
+        @param content: 数据内容
+        @param start: 起始长度
+        @param end: 结束长度
+        @return content: 解密的数据
+        """
+        if not content:
+            return ''
+        for i in range(start, end):
+            content = base64.b64decode(content)
+            content = content.decode('utf-8')
+            content = content[i:-i]
+        return content

+ 4 - 0
Service/DevicePushService.py

@@ -264,6 +264,8 @@ class DevicePushService:
                 msg_type = '摄像头休眠'
                 msg_type = '摄像头休眠'
             elif etype == 703:
             elif etype == 703:
                 msg_type = '摄像头唤醒'
                 msg_type = '摄像头唤醒'
+            elif etype == 606:
+                msg_type = '一键通话'
             else:
             else:
                 msg_type = ''
                 msg_type = ''
             if is_sys:
             if is_sys:
@@ -277,6 +279,8 @@ class DevicePushService:
                 msg_type = 'Camera sleep'
                 msg_type = 'Camera sleep'
             elif etype == 703:
             elif etype == 703:
                 msg_type = 'Camera wake'
                 msg_type = 'Camera wake'
+            elif etype == 606:
+                msg_type = 'Push to talk'
             else:
             else:
                 msg_type = ''
                 msg_type = ''
             if is_sys:
             if is_sys: