Browse Source

修改按下门铃推送类型

locky 9 months ago
parent
commit
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 AnsjerPush.config import CONFIG_EUR, CONFIG_INFO, CONFIG_US
 from Object.RedisObject import RedisObject
 from Object.RedisObject import RedisObject
 from Service.DevicePushService import DevicePushService
 from Service.DevicePushService import DevicePushService
+from Object.enums.EventTypeEnum import EventTypeEnumObj
 
 
 TIME_LOGGER = logging.getLogger('time')
 TIME_LOGGER = logging.getLogger('time')
 ERROR_INFO_LOGGER = logging.getLogger('error_info')
 ERROR_INFO_LOGGER = logging.getLogger('error_info')
@@ -79,7 +80,7 @@ class NotificationV2View(View):
             req_limiting = '{}_{}_{}_ptl'.format(uid, channel, event_type)
             req_limiting = '{}_{}_{}_ptl'.format(uid, channel, event_type)
             cache_req_limiting = redis_obj.get_data(key=req_limiting)  # 获取请求限流缓存数据
             cache_req_limiting = redis_obj.get_data(key=req_limiting)  # 获取请求限流缓存数据
             cache_app_push = redis_obj.get_data(key=push_interval)  # 获取APP推送消息时间间隔缓存数据
             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:  # 限流存在则直接返回
                 if cache_req_limiting:  # 限流存在则直接返回
                     return JsonResponse(status=200, data={'code': 0, 'msg': 'Push again in one minute'})
                     return JsonResponse(status=200, data={'code': 0, 'msg': 'Push again in one minute'})
             redis_obj.set_data(key=req_limiting, val=1, expire=60)  # 当缓存不存在限流数据 重新设置一分钟请求一次
             redis_obj.set_data(key=req_limiting, val=1, expire=60)  # 当缓存不存在限流数据 重新设置一分钟请求一次
@@ -106,7 +107,7 @@ class NotificationV2View(View):
 
 
             # APP消息提醒推送间隔
             # APP消息提醒推送间隔
             detect_interval = uid_set_push_list[0]['uid_set__detect_interval']
             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:
                 if not cache_app_push:
                     # 缓存APP提醒推送间隔 默认1分钟提醒一次
                     # 缓存APP提醒推送间隔 默认1分钟提醒一次
                     DevicePushService.cache_push_detect_interval(redis_obj, push_interval, detect_interval,
                     DevicePushService.cache_push_detect_interval(redis_obj, push_interval, detect_interval,
@@ -159,7 +160,7 @@ class NotificationV2View(View):
             push_thread.start()
             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))
                 TIME_LOGGER.info('推送响应,uid:{},n_time:{},事件类型:{}'.format(uid, n_time, event_type))
                 return JsonResponse(status=200, data={'code': 0, 'msg': 'success'})
                 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.ETkObject import ETkObject
 from Object.OCIObjectStorage import OCIObjectStorage
 from Object.OCIObjectStorage import OCIObjectStorage
 from Object.UidTokenObject import UidTokenObject
 from Object.UidTokenObject import UidTokenObject
+from Object.enums.EventTypeEnum import EventTypeEnumObj
 from Object.utils import LocalDateTimeUtil
 from Object.utils import LocalDateTimeUtil
 from Service.CommonService import CommonService
 from Service.CommonService import CommonService
 from Service.EquipmentInfoService import EquipmentInfoService, EQUIPMENT_INFO_DICT
 from Service.EquipmentInfoService import EquipmentInfoService, EQUIPMENT_INFO_DICT
@@ -103,7 +104,7 @@ class DevicePushService:
         @param button: 按钮
         @param button: 按钮
         @return: uid_push_qs
         @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) \
             uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid, uid_set__detect_status=1) \
                 .exclude(token_val='0'). \
                 .exclude(token_val='0'). \
                 values('token_val', 'app_type', 'appBundleId', 'm_code', 'push_type', 'userID_id', 'userID__NickName',
                 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__channel', 'uid_set__ai_type', 'uid_set__device_type', 'uid_set__new_detect_interval',
                        'uid_set__msg_notify')
                        'uid_set__msg_notify')
         else:
         else:
-            # 一键通话只推主用户
+            # 一键通话,按下门铃只推主用户
             device_info_qs = Device_Info.objects.filter(UID=uid).values('vodPrimaryUserID')
             device_info_qs = Device_Info.objects.filter(UID=uid).values('vodPrimaryUserID')
             primary_user_id = device_info_qs[0]['vodPrimaryUserID']
             primary_user_id = device_info_qs[0]['vodPrimaryUserID']
             if event_type == 607:  # 音视频通话根据用户按钮来推送
             if event_type == 607:  # 音视频通话根据用户按钮来推送
@@ -179,7 +180,7 @@ class DevicePushService:
         try:
         try:
             uid = params['uid']
             uid = params['uid']
             params['event_tag'] = cls.get_event_tag(params['ai_type'], params['event_type'], params['detection'])
             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(
                 cls.is_send_app_push(
                     params['event_type'], params['event_tag'], params['app_push_config'], params['app_push'],
                     params['event_type'], params['event_tag'], params['app_push_config'], params['app_push'],
                     uid, params['channel'])
                     uid, params['channel'])
@@ -202,7 +203,7 @@ class DevicePushService:
                     tz = up['tz']
                     tz = up['tz']
                     if tz is None or tz == '':
                     if tz is None or tz == '':
                         tz = 0
                         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']
                         push_kwargs['jg_token_val'] = up['jg_token_val']
                     else:
                     else:
                         if 'jg_token_val' in push_kwargs:
                         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
                     end = 0
                     # 缓存数据多于100条,批量保存前100条,否则保存全部
                     # 缓存数据多于100条,批量保存前100条,否则保存全部
                     equipment_info_len = redis_obj.llen(equipment_info_key)
                     equipment_info_len = redis_obj.llen(equipment_info_key)
@@ -462,7 +464,7 @@ class DevicePushService:
                     huawei_push_object = HuaweiPushObject()
                     huawei_push_object = HuaweiPushObject()
                     huawei_push_object.send_push_notify_message(**push_kwargs)
                     huawei_push_object.send_push_notify_message(**push_kwargs)
                 elif push_type == 4:  # android xmpush
                 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'
                         push_channel = 'push_to_talk'
                     else:
                     else:
                         push_channel = 'device_reminder'
                         push_channel = 'device_reminder'
@@ -478,7 +480,7 @@ class DevicePushService:
                 elif push_type == 8:  # android honorpush
                 elif push_type == 8:  # android honorpush
                     push_result = PushObject.android_honorpush(**push_kwargs)
                     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()
                 close_old_connections()
                 # 写入日志表
                 # 写入日志表
                 PushLog.objects.create(uid=uid, event_type=kwargs['event_type'], created_time=int(time.time()),
                 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'
                 msg_type = 'Camera sleep'
             elif event_type == 703:
             elif event_type == 703:
                 msg_type = 'Camera wake'
                 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'
                 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)
                 msg_type = ''.join([DevicePushService.get_event_type_text(lang, item, dealings_type)
                                     for item in event_list])
                                     for item in event_list])
             if is_sys:
             if is_sys:
@@ -694,7 +696,7 @@ class DevicePushService:
                 'extra.uid': uid,
                 'extra.uid': uid,
                 'extra.channel': channel,
                 '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'
                 data['extra.sound_uri'] = 'android.resource://com.ansjer.zccloud_ab/raw/phone_call'
             headers = {
             headers = {
                 'Authorization': 'key={}'.format(app_secret)
                 'Authorization': 'key={}'.format(app_secret)
@@ -718,7 +720,7 @@ class DevicePushService:
         android 国内oppo APP消息提醒推送
         android 国内oppo APP消息提醒推送
         """
         """
         try:
         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']
                 channel_id = XM_PUSH_CHANNEL_ID['push_to_talk']
             app_key = OPPOPUSH_CONFIG[appBundleId]['Key']
             app_key = OPPOPUSH_CONFIG[appBundleId]['Key']
             master_secret = OPPOPUSH_CONFIG[appBundleId]['Secret']
             master_secret = OPPOPUSH_CONFIG[appBundleId]['Secret']
@@ -766,7 +768,7 @@ class DevicePushService:
             if response.status_code == 200:
             if response.status_code == 200:
                 LOGGING.info(
                 LOGGING.info(
                     "oppo推送返回值:{},uid:{},time:{},event:{}".format(response.json(), uid, now_time, event_type))
                     "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,
                     PushObject.jpush_transparent_transmission(msg_title, msg_text, appBundleId, jg_token_val,
                                                               extra_data)
                                                               extra_data)
                 return True
                 return True

+ 2 - 1
Service/HuaweiPushService/HuaweiPushService.py

@@ -1,6 +1,7 @@
 import json
 import json
 
 
 from AnsjerPush.config import LOGGER
 from AnsjerPush.config import LOGGER
+from Object.enums.EventTypeEnum import EventTypeEnumObj
 from Service.HuaweiPushService import push_admin
 from Service.HuaweiPushService import push_admin
 from Service.HuaweiPushService.push_admin import messaging
 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,
         send_succeed = self.send_notify_message(msg_title, msg_text, image_url, uid, nickname,
                                                 event_type, n_time, token_val, channel)
                                                 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)
             self.send_data_message(uid, event_type, n_time, token_val, channel)
 
 
         return send_succeed
         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 Model.models import UidPushModel
 from Object.RedisObject import RedisObject
 from Object.RedisObject import RedisObject
 from Object.S3Email import S3Email
 from Object.S3Email import S3Email
+from Object.enums.EventTypeEnum import EventTypeEnumObj
 from Service.CommonService import CommonService
 from Service.CommonService import CommonService
 from Service.VivoPushService.push_admin.APIMessage import PushMessage
 from Service.VivoPushService.push_admin.APIMessage import PushMessage
 from Service.VivoPushService.push_admin.APISender import APISender
 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,
                          'received_at': n_time, 'event_time': n_time, 'event_type': event_type, 'nickname': nickname,
                          'image_url': launch_image
                          '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',
             payload = apns2.Payload(alert=alert, custom=push_data, sound=sound, category='myCategory',
                                     mutable_content=True)
                                     mutable_content=True)
             n = apns2.Notification(payload=payload, priority=apns2.PRIORITY_LOW)
             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,
                          'received_at': n_time, 'event_time': n_time, 'event_type': event_type, 'nickname': nickname,
                          'uid': uid, 'channel': channel
                          '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['priority'] = 'high'
                 push_data['content_available'] = True
                 push_data['content_available'] = True
                 push_data['direct_boot_ok'] = 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,
                          'received_at': n_time, 'event_time': n_time, 'event_type': event_type, 'nickname': nickname,
                          'uid': uid, 'channel': channel
                          '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['priority'] = 'high'
                 push_data['content_available'] = True
                 push_data['content_available'] = True
                 push_data['direct_boot_ok'] = True
                 push_data['direct_boot_ok'] = True
@@ -252,7 +253,7 @@ class PushObject:
             _jpush = jpush.JPush(app_key, master_secret)
             _jpush = jpush.JPush(app_key, master_secret)
             push = _jpush.create_push()
             push = _jpush.create_push()
             push.audience = jpush.registration_id(token_val)
             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'
                 channel_id = '111934'
             else:
             else:
                 channel_id = '1'
                 channel_id = '1'
@@ -386,7 +387,7 @@ class PushObject:
                 .message_dict()
                 .message_dict()
             rec = sender_send.send(message)
             rec = sender_send.send(message)
             LOGGER.info('vivo推送结果:{}, 设备uid:{}'.format(rec, uid))
             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)
                 PushObject.jpush_transparent_transmission(msg_title, msg_text, app_bundle_id, jg_token_val, push_data)
             return True
             return True
         except Exception as e:
         except Exception as e:
@@ -462,7 +463,7 @@ class PushObject:
 
 
             response = requests.post(push_url, data=push_data, headers=headers)
             response = requests.post(push_url, data=push_data, headers=headers)
             LOGGER.info("oppo推送返回值:{}".format(response.json()))
             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)
                 PushObject.jpush_transparent_transmission(msg_title, msg_text, app_bundle_id, jg_token_val, extra_data)
             return True
             return True
         except Exception as e:
         except Exception as e:
@@ -593,7 +594,7 @@ class PushObject:
             response = requests.post(push_url, json=push_data, headers=headers)
             response = requests.post(push_url, json=push_data, headers=headers)
             LOGGER.info("uid:{},时间:{},荣耀推送通知返回值:{}".format(uid, n_time, response.json()))
             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 = {
                 push_data = {
                     "data": json.dumps(extra_data),
                     "data": json.dumps(extra_data),
                     "token": [token_val]
                     "token": [token_val]