Procházet zdrojové kódy

修改按下门铃推送类型

locky před 7 měsíci
rodič
revize
f32642be8c

+ 4 - 3
Controller/DetectControllerV2.py

@@ -8,6 +8,7 @@ from django.views.generic.base import View
 from AnsjerPush.config import CONFIG_EUR, CONFIG_INFO, CONFIG_US
 from Object.RedisObject import RedisObject
 from Service.DevicePushService import DevicePushService
+from Object.enums.EventTypeEnum import EventTypeEnumObj
 
 TIME_LOGGER = logging.getLogger('time')
 ERROR_INFO_LOGGER = logging.getLogger('error_info')
@@ -79,7 +80,7 @@ class NotificationV2View(View):
             req_limiting = '{}_{}_{}_ptl'.format(uid, channel, event_type)
             cache_req_limiting = redis_obj.get_data(key=req_limiting)  # 获取请求限流缓存数据
             cache_app_push = redis_obj.get_data(key=push_interval)  # 获取APP推送消息时间间隔缓存数据
-            if event_type not in [606, 607, 1022, 1023]:
+            if event_type not in EventTypeEnumObj.UNRESTRICTED_FREQUENCY_PUSH_EVENT_TYPE_LIST.value:
                 if cache_req_limiting:  # 限流存在则直接返回
                     return JsonResponse(status=200, data={'code': 0, 'msg': 'Push again in one minute'})
             redis_obj.set_data(key=req_limiting, val=1, expire=60)  # 当缓存不存在限流数据 重新设置一分钟请求一次
@@ -106,7 +107,7 @@ class NotificationV2View(View):
 
             # APP消息提醒推送间隔
             detect_interval = uid_set_push_list[0]['uid_set__detect_interval']
-            if event_type not in [606, 607, 1022, 1023]:
+            if event_type not in EventTypeEnumObj.UNRESTRICTED_FREQUENCY_PUSH_EVENT_TYPE_LIST.value:
                 if not cache_app_push:
                     # 缓存APP提醒推送间隔 默认1分钟提醒一次
                     DevicePushService.cache_push_detect_interval(redis_obj, push_interval, detect_interval,
@@ -159,7 +160,7 @@ class NotificationV2View(View):
             push_thread.start()
 
             # 视频通话不返回图片链接
-            if event_type == 607:
+            if event_type in [607, 1022]:
                 TIME_LOGGER.info('推送响应,uid:{},n_time:{},事件类型:{}'.format(uid, n_time, event_type))
                 return JsonResponse(status=200, data={'code': 0, 'msg': 'success'})
 

+ 25 - 0
Object/enums/EventTypeEnum.py

@@ -0,0 +1,25 @@
+# @Author    : Rocky
+# @File      : EventTypeEnum.py
+# @Time      : 2024/12/25 9:45
+from enum import Enum, unique
+
+
+@unique
+class EventTypeEnumObj(Enum):
+    ONE_CLICK_CALL = 606                # 一键通话
+    VIDEO_CALL = 607                    # 视频通话
+    PRESS_THE_DOORBELL = 1022           # 按下门铃
+    CHILD_PROTECTION_MODE = 1023        # 儿童保护模式
+    # 不限频推送事件类型列表
+    UNRESTRICTED_FREQUENCY_PUSH_EVENT_TYPE_LIST = [
+        ONE_CLICK_CALL,
+        VIDEO_CALL,
+        PRESS_THE_DOORBELL,
+        CHILD_PROTECTION_MODE
+    ]
+    # 透传推送事件类型列表
+    DATA_PUSH_EVENT_TYPE_LIST = [
+        ONE_CLICK_CALL,
+        VIDEO_CALL,
+        PRESS_THE_DOORBELL
+    ]

+ 14 - 12
Service/DevicePushService.py

@@ -29,6 +29,7 @@ from Model.models import UidPushModel, SysMsgModel, DeviceSharePermission, Devic
 from Object.ETkObject import ETkObject
 from Object.OCIObjectStorage import OCIObjectStorage
 from Object.UidTokenObject import UidTokenObject
+from Object.enums.EventTypeEnum import EventTypeEnumObj
 from Object.utils import LocalDateTimeUtil
 from Service.CommonService import CommonService
 from Service.EquipmentInfoService import EquipmentInfoService, EQUIPMENT_INFO_DICT
@@ -103,7 +104,7 @@ class DevicePushService:
         @param button: 按钮
         @return: uid_push_qs
         """
-        if event_type not in [606, 607]:
+        if event_type not in EventTypeEnumObj.DATA_PUSH_EVENT_TYPE_LIST.value:
             uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid, uid_set__detect_status=1) \
                 .exclude(token_val='0'). \
                 values('token_val', 'app_type', 'appBundleId', 'm_code', 'push_type', 'userID_id', 'userID__NickName',
@@ -111,7 +112,7 @@ class DevicePushService:
                        'uid_set__channel', 'uid_set__ai_type', 'uid_set__device_type', 'uid_set__new_detect_interval',
                        'uid_set__msg_notify')
         else:
-            # 一键通话只推主用户
+            # 一键通话,按下门铃只推主用户
             device_info_qs = Device_Info.objects.filter(UID=uid).values('vodPrimaryUserID')
             primary_user_id = device_info_qs[0]['vodPrimaryUserID']
             if event_type == 607:  # 音视频通话根据用户按钮来推送
@@ -179,7 +180,7 @@ class DevicePushService:
         try:
             uid = params['uid']
             params['event_tag'] = cls.get_event_tag(params['ai_type'], params['event_type'], params['detection'])
-            is_app_push = True if params['event_type'] in [606, 607] else \
+            is_app_push = True if params['event_type'] in EventTypeEnumObj.DATA_PUSH_EVENT_TYPE_LIST.value else \
                 cls.is_send_app_push(
                     params['event_type'], params['event_tag'], params['app_push_config'], params['app_push'],
                     uid, params['channel'])
@@ -202,7 +203,7 @@ class DevicePushService:
                     tz = up['tz']
                     if tz is None or tz == '':
                         tz = 0
-                    if params['event_type'] in [606, 607] and push_type in [5, 6]:
+                    if params['event_type'] in EventTypeEnumObj.DATA_PUSH_EVENT_TYPE_LIST.value and push_type in [5, 6]:
                         push_kwargs['jg_token_val'] = up['jg_token_val']
                     else:
                         if 'jg_token_val' in push_kwargs:
@@ -313,7 +314,8 @@ class DevicePushService:
 
                 # 一键通话和视频通话需要实时写入数据
                 # 正式服通过定时任务批量写入数据
-                if params['event_type'] in [606, 607] or CONFIG_INFO == CONFIG_TEST:
+                if params['event_type'] in EventTypeEnumObj.DATA_PUSH_EVENT_TYPE_LIST.value or \
+                        CONFIG_INFO == CONFIG_TEST:
                     end = 0
                     # 缓存数据多于100条,批量保存前100条,否则保存全部
                     equipment_info_len = redis_obj.llen(equipment_info_key)
@@ -462,7 +464,7 @@ class DevicePushService:
                     huawei_push_object = HuaweiPushObject()
                     huawei_push_object.send_push_notify_message(**push_kwargs)
                 elif push_type == 4:  # android xmpush
-                    if kwargs['event_type'] in [606, 607]:
+                    if kwargs['event_type'] in EventTypeEnumObj.DATA_PUSH_EVENT_TYPE_LIST.value:
                         push_channel = 'push_to_talk'
                     else:
                         push_channel = 'device_reminder'
@@ -478,7 +480,7 @@ class DevicePushService:
                 elif push_type == 8:  # android honorpush
                     push_result = PushObject.android_honorpush(**push_kwargs)
 
-            if kwargs['event_type'] in [606, 607]:
+            if kwargs['event_type'] in EventTypeEnumObj.DATA_PUSH_EVENT_TYPE_LIST.value:
                 close_old_connections()
                 # 写入日志表
                 PushLog.objects.create(uid=uid, event_type=kwargs['event_type'], created_time=int(time.time()),
@@ -647,9 +649,9 @@ class DevicePushService:
                 msg_type = 'Camera sleep'
             elif event_type == 703:
                 msg_type = 'Camera wake'
-            elif event_type in [606, 607]:
+            elif event_type in EventTypeEnumObj.DATA_PUSH_EVENT_TYPE_LIST.value:
                 msg_type = 'Someone is calling, please click to view'
-            elif event_type not in [606, 607] and ai_type > 0 and event_list:
+            elif event_type not in EventTypeEnumObj.DATA_PUSH_EVENT_TYPE_LIST.value and ai_type > 0 and event_list:
                 msg_type = ''.join([DevicePushService.get_event_type_text(lang, item, dealings_type)
                                     for item in event_list])
             if is_sys:
@@ -694,7 +696,7 @@ class DevicePushService:
                 'extra.uid': uid,
                 'extra.channel': channel,
             }
-            if event_type in [606, 607]:
+            if event_type in EventTypeEnumObj.DATA_PUSH_EVENT_TYPE_LIST.value:
                 data['extra.sound_uri'] = 'android.resource://com.ansjer.zccloud_ab/raw/phone_call'
             headers = {
                 'Authorization': 'key={}'.format(app_secret)
@@ -718,7 +720,7 @@ class DevicePushService:
         android 国内oppo APP消息提醒推送
         """
         try:
-            if event_type in [606, 607]:
+            if event_type in EventTypeEnumObj.DATA_PUSH_EVENT_TYPE_LIST.value:
                 channel_id = XM_PUSH_CHANNEL_ID['push_to_talk']
             app_key = OPPOPUSH_CONFIG[appBundleId]['Key']
             master_secret = OPPOPUSH_CONFIG[appBundleId]['Secret']
@@ -766,7 +768,7 @@ class DevicePushService:
             if response.status_code == 200:
                 LOGGING.info(
                     "oppo推送返回值:{},uid:{},time:{},event:{}".format(response.json(), uid, now_time, event_type))
-                if event_type in [606, 607]:
+                if event_type in EventTypeEnumObj.DATA_PUSH_EVENT_TYPE_LIST.value:
                     PushObject.jpush_transparent_transmission(msg_title, msg_text, appBundleId, jg_token_val,
                                                               extra_data)
                 return True

+ 2 - 1
Service/HuaweiPushService/HuaweiPushService.py

@@ -1,6 +1,7 @@
 import json
 
 from AnsjerPush.config import LOGGER
+from Object.enums.EventTypeEnum import EventTypeEnumObj
 from Service.HuaweiPushService import push_admin
 from Service.HuaweiPushService.push_admin import messaging
 
@@ -41,7 +42,7 @@ class HuaweiPushObject:
 
         send_succeed = self.send_notify_message(msg_title, msg_text, image_url, uid, nickname,
                                                 event_type, n_time, token_val, channel)
-        if int(event_type) in [606, 607]:
+        if int(event_type) in EventTypeEnumObj.DATA_PUSH_EVENT_TYPE_LIST.value:
             self.send_data_message(uid, event_type, n_time, token_val, channel)
 
         return send_succeed

+ 8 - 7
Service/PushService.py

@@ -23,6 +23,7 @@ from AnsjerPush.config import APP_BUNDLE_DICT, APNS_MODE, BASE_DIR, APNS_CONFIG,
 from Model.models import UidPushModel
 from Object.RedisObject import RedisObject
 from Object.S3Email import S3Email
+from Object.enums.EventTypeEnum import EventTypeEnumObj
 from Service.CommonService import CommonService
 from Service.VivoPushService.push_admin.APIMessage import PushMessage
 from Service.VivoPushService.push_admin.APISender import APISender
@@ -130,7 +131,7 @@ class PushObject:
                          'received_at': n_time, 'event_time': n_time, 'event_type': event_type, 'nickname': nickname,
                          'image_url': launch_image
                          }
-            sound = 'call_phone.mp3' if event_type in [606, 607] else 'default'
+            sound = 'call_phone.mp3' if event_type in EventTypeEnumObj.DATA_PUSH_EVENT_TYPE_LIST.value else 'default'
             payload = apns2.Payload(alert=alert, custom=push_data, sound=sound, category='myCategory',
                                     mutable_content=True)
             n = apns2.Notification(payload=payload, priority=apns2.PRIORITY_LOW)
@@ -167,7 +168,7 @@ class PushObject:
                          'received_at': n_time, 'event_time': n_time, 'event_type': event_type, 'nickname': nickname,
                          'uid': uid, 'channel': channel
                          }
-            if event_type in [606, 607]:
+            if event_type in EventTypeEnumObj.DATA_PUSH_EVENT_TYPE_LIST.value:
                 push_data['priority'] = 'high'
                 push_data['content_available'] = True
                 push_data['direct_boot_ok'] = True
@@ -209,7 +210,7 @@ class PushObject:
                          'received_at': n_time, 'event_time': n_time, 'event_type': event_type, 'nickname': nickname,
                          'uid': uid, 'channel': channel
                          }
-            if event_type in [606, 607]:
+            if event_type in EventTypeEnumObj.DATA_PUSH_EVENT_TYPE_LIST.value:
                 push_data['priority'] = 'high'
                 push_data['content_available'] = True
                 push_data['direct_boot_ok'] = True
@@ -252,7 +253,7 @@ class PushObject:
             _jpush = jpush.JPush(app_key, master_secret)
             push = _jpush.create_push()
             push.audience = jpush.registration_id(token_val)
-            if event_type in [606, 607]:
+            if event_type in EventTypeEnumObj.DATA_PUSH_EVENT_TYPE_LIST.value:
                 channel_id = '111934'
             else:
                 channel_id = '1'
@@ -386,7 +387,7 @@ class PushObject:
                 .message_dict()
             rec = sender_send.send(message)
             LOGGER.info('vivo推送结果:{}, 设备uid:{}'.format(rec, uid))
-            if rec['result'] == 0 and event_type in [606, 607]:
+            if rec['result'] == 0 and event_type in EventTypeEnumObj.DATA_PUSH_EVENT_TYPE_LIST.value:
                 PushObject.jpush_transparent_transmission(msg_title, msg_text, app_bundle_id, jg_token_val, push_data)
             return True
         except Exception as e:
@@ -462,7 +463,7 @@ class PushObject:
 
             response = requests.post(push_url, data=push_data, headers=headers)
             LOGGER.info("oppo推送返回值:{}".format(response.json()))
-            if response.status_code == 200 and event_type in [606, 607]:
+            if response.status_code == 200 and event_type in EventTypeEnumObj.DATA_PUSH_EVENT_TYPE_LIST.value:
                 PushObject.jpush_transparent_transmission(msg_title, msg_text, app_bundle_id, jg_token_val, extra_data)
             return True
         except Exception as e:
@@ -593,7 +594,7 @@ class PushObject:
             response = requests.post(push_url, json=push_data, headers=headers)
             LOGGER.info("uid:{},时间:{},荣耀推送通知返回值:{}".format(uid, n_time, response.json()))
             # 一键通话透传推送
-            if int(event_type) in [606, 607]:
+            if int(event_type) in EventTypeEnumObj.DATA_PUSH_EVENT_TYPE_LIST.value:
                 push_data = {
                     "data": json.dumps(extra_data),
                     "token": [token_val]