Просмотр исходного кода

Merge branch 'test' of http://192.168.136.99:3000/servers/ASJPush into peng

peng 2 лет назад
Родитель
Сommit
ae24e04f72

+ 1 - 0
AnsjerPush/dev_config/local_settings.py

@@ -26,6 +26,7 @@ MIDDLEWARE = [
     'django.contrib.auth.middleware.AuthenticationMiddleware',
     'django.contrib.messages.middleware.MessageMiddleware',
     'django.middleware.clickjacking.XFrameOptionsMiddleware',
+    'MiddleWare.requestRecord.RequestRecordMiddleware',  # 记录请求信息
 ]
 
 ROOT_URLCONF = 'AnsjerPush.urls'

+ 1 - 0
AnsjerPush/test_config/test_settings.py

@@ -27,6 +27,7 @@ MIDDLEWARE = [
     'django.contrib.auth.middleware.AuthenticationMiddleware',
     'django.contrib.messages.middleware.MessageMiddleware',
     'django.middleware.clickjacking.XFrameOptionsMiddleware',
+    'MiddleWare.requestRecord.RequestRecordMiddleware',  # 记录请求信息
 ]
 
 ROOT_URLCONF = 'AnsjerPush.urls'

+ 7 - 0
MiddleWare/__init__.py

@@ -0,0 +1,7 @@
+# -*- coding: utf-8 -*-
+"""
+@Time : 2023/5/12 10:00
+@Auth : guanhailong
+@File :__init__.py.py
+@IDE :PyCharm
+"""

+ 36 - 0
MiddleWare/requestRecord.py

@@ -0,0 +1,36 @@
+# -*- coding: utf-8 -*-
+"""
+@Time : 2021/9/22 17:08
+@Auth : Locky
+@File :requestRecord.py
+@IDE :PyCharm
+"""
+import json
+import time
+from django.utils.deprecation import MiddlewareMixin
+from AnsjerPush.config import LOGGER
+
+
+class RequestRecordMiddleware(MiddlewareMixin):
+    def Request(self, request):
+        request.start_time = time.time()
+
+    def Response(self, request, response):
+        try:
+            method = request.method
+            url = request.path
+
+            # 获取请求参数并转为字符串
+            if method == 'GET':
+                parameter = json.dumps(request.GET.dict())
+            elif method == 'POST':
+                parameter = json.dumps(request.POST.dict())
+            else:
+                parameter = ''
+            content = eval(str(response.content, 'utf-8'))  # bytes 转为 dict
+            # 请求是否成功
+            if content['result_code'] != 0 or content['code'] != 0:
+                LOGGER.info('请求路径:{}, 请求方式:{}, 输入数据:{}, 输出数据:{}, 响应状态:{}'.format(url, method, parameter, content,
+                                                                                 response.status_code))
+        finally:
+            return response

+ 8 - 4
Service/DevicePushService.py

@@ -377,7 +377,9 @@ class DevicePushService:
         event_type = int(event_type)
         device_type = int(device_type)
         if lang == 'cn':
-            if event_type == 704:
+            if event_type == 51:
+                msg_type = '检测到画面变化'
+            elif event_type == 704:
                 msg_type = '剩余电量 ' + electricity
             elif event_type == 702:
                 msg_type = '摄像头休眠'
@@ -407,9 +409,11 @@ class DevicePushService:
                 if device_type in MULTI_CHANNEL_TYPE_LIST:
                     send_text = '{} 通道:{} 日期:{}'.format(msg_type, channel, n_date)
                 else:
-                    send_text = '{} 日期:{}'.format(msg_type, channel, n_date)
+                    send_text = '{} 日期:{}'.format(msg_type, n_date)
         else:
-            if event_type == 704:
+            if event_type == 51:
+                msg_type = 'Screen change detected'
+            elif event_type == 704:
                 msg_type = 'Battery remaining ' + electricity
             elif event_type == 702:
                 msg_type = 'Camera sleep'
@@ -439,7 +443,7 @@ class DevicePushService:
                 if device_type in MULTI_CHANNEL_TYPE_LIST:
                     send_text = '{} channel:{} date:{}'.format(msg_type, channel, n_date)
                 else:
-                    send_text = '{} date:{}'.format(msg_type, channel, n_date)
+                    send_text = '{} date:{}'.format(msg_type, n_date)
         return send_text
 
     @staticmethod