ソースを参照

列表替换枚举

locky 4 ヶ月 前
コミット
8d53aa00c7

+ 10 - 1
AnsjerPush/config.py

@@ -147,8 +147,17 @@ APP_BUNDLE_DICT = {
     'com.ansjer.customizedc_a': 'PatrolSecure',
 }
 
-SYS_EVENT_TYPE_LIST = [702, 703, 704, 706]
 MULTI_CHANNEL_TYPE_LIST = [1, 2, 3, 4, 10001]
+# 事件类型,完整内容见企业微信的《开发类型定义》文档的推送类型表
+# 系统消息事件类型
+SYS_EVENT_TYPE_LIST = [702, 703, 704, 706]
+# 不限频推送事件类型
+UNRESTRICTED_FREQUENCY_PUSH_EVENT_TYPE_LIST = [606, 607, 706, 1022, 1023]
+# 透传推送事件类型列表(音视频通话)
+DATA_PUSH_EVENT_TYPE_LIST = [606, 607, 1022]
+# 主用户推送事件类型列表
+PRIMARY_USERS_PUSH_EVENT_TYPE_LIST = [606, 607, 706, 1022]
+
 
 # AI识别标签
 AI_IDENTIFICATION_TAGS_DICT = {

+ 3 - 3
Controller/DetectControllerV2.py

@@ -5,7 +5,7 @@ import threading
 from django.http import JsonResponse
 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, UNRESTRICTED_FREQUENCY_PUSH_EVENT_TYPE_LIST
 from Object.RedisObject import RedisObject
 from Service.DevicePushService import DevicePushService
 from Object.enums.EventTypeEnum import EventTypeEnumObj
@@ -81,7 +81,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 EventTypeEnumObj.UNRESTRICTED_FREQUENCY_PUSH_EVENT_TYPE_LIST.value:
+            if event_type not in UNRESTRICTED_FREQUENCY_PUSH_EVENT_TYPE_LIST:
                 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)  # 当缓存不存在限流数据 重新设置一分钟请求一次
@@ -109,7 +109,7 @@ class NotificationV2View(View):
 
             # APP消息提醒推送间隔
             detect_interval = uid_set_push_list[0]['uid_set__detect_interval']
-            if event_type not in EventTypeEnumObj.UNRESTRICTED_FREQUENCY_PUSH_EVENT_TYPE_LIST.value:
+            if event_type not in UNRESTRICTED_FREQUENCY_PUSH_EVENT_TYPE_LIST:
                 if not cache_app_push:
                     # 缓存APP提醒推送间隔 默认1分钟提醒一次
                     DevicePushService.cache_push_detect_interval(redis_obj, push_interval, detect_interval,

+ 4 - 3
Service/CommonService.py

@@ -13,7 +13,8 @@ from django.core import serializers
 from django.utils import timezone
 from pyipip import IPIPDatabase
 
-from AnsjerPush.config import BASE_DIR, ACCESS_KEY_ID, SECRET_ACCESS_KEY, REGION_NAME, PUSH_BUCKET
+from AnsjerPush.config import BASE_DIR, ACCESS_KEY_ID, SECRET_ACCESS_KEY, REGION_NAME, PUSH_BUCKET, SYS_EVENT_TYPE_LIST, \
+    DATA_PUSH_EVENT_TYPE_LIST
 from Object.enums.EventTypeEnum import EventTypeEnumObj
 
 
@@ -337,8 +338,8 @@ class CommonService:
         # 跳转类型,1:推送消息,2:系统消息,3:音视频通话消息
         jump_type = 1
         event_type = int(event_type)
-        if event_type in EventTypeEnumObj.SYS_MSG_EVENT_TYPE_LIST.value:
+        if event_type in SYS_EVENT_TYPE_LIST:
             jump_type = 2
-        elif event_type in EventTypeEnumObj.DATA_PUSH_EVENT_TYPE_LIST.value:
+        elif event_type in DATA_PUSH_EVENT_TYPE_LIST:
             jump_type = 3
         return jump_type

+ 17 - 16
Service/DevicePushService.py

@@ -23,7 +23,8 @@ from AnsjerPush.Config.aiConfig import DEVICE_EVENT_TYPE, ALGORITHM_COMBO_TYPES
 from AnsjerPush.MessageConfig import EVENT_CONFIGS, DEFAULT_TEXTS, CHANNEL_MAP, MSG_CONFIG
 from AnsjerPush.config import CONFIG_INFO, CONFIG_CN, MULTI_CHANNEL_TYPE_LIST, SYS_EVENT_TYPE_LIST, AWS_ACCESS_KEY_ID, \
     AWS_SECRET_ACCESS_KEY, EVENT_DICT, EVENT_DICT_CN, CONFIG_TEST, HUAWEICLOUD_AK, HUAWEICLOUD_SK, \
-    HUAWEICLOUD_OBS_SERVER, HUAWEICLOUD_PUSH_BUKET, OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET, JPUSH_UID_LIST
+    HUAWEICLOUD_OBS_SERVER, HUAWEICLOUD_PUSH_BUKET, OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET, JPUSH_UID_LIST, \
+    DATA_PUSH_EVENT_TYPE_LIST, PRIMARY_USERS_PUSH_EVENT_TYPE_LIST
 from AnsjerPush.config import XMPUSH_CONFIG, OPPOPUSH_CONFIG, XM_PUSH_CHANNEL_ID, XM_PUSH_CHANNEL_DICT
 from Model.models import UidPushModel, SysMsgModel, DeviceSharePermission, DeviceChannelUserSet, \
     DeviceChannelUserPermission, UidSetModel, Device_Info, UserAudioVideoPush, PushLog
@@ -108,7 +109,7 @@ class DevicePushService:
         @param button: 按钮
         @return: uid_push_qs
         """
-        if event_type not in EventTypeEnumObj.PRIMARY_USERS_PUSH_EVENT_TYPE_LIST.value:
+        if event_type not in PRIMARY_USERS_PUSH_EVENT_TYPE_LIST:
             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',
@@ -188,7 +189,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 EventTypeEnumObj.PRIMARY_USERS_PUSH_EVENT_TYPE_LIST.value \
+            is_app_push = True if params['event_type'] in PRIMARY_USERS_PUSH_EVENT_TYPE_LIST \
                 else cls.is_send_app_push(
                 params['event_type'], params['event_tag'], params['app_push_config'], params['app_push'],
                 uid, params['channel'])
@@ -212,7 +213,7 @@ class DevicePushService:
                     tz = up['tz']
                     if tz is None or tz == '':
                         tz = 0
-                    if params['event_type'] in EventTypeEnumObj.DATA_PUSH_EVENT_TYPE_LIST.value and push_type in [5, 6]:
+                    if params['event_type'] in DATA_PUSH_EVENT_TYPE_LIST and push_type in [5, 6]:
                         process_token = up['jg_token_val']
                         push_kwargs['jg_token_val'] = up['jg_token_val']
                     else:
@@ -329,7 +330,7 @@ class DevicePushService:
 
                 # 一键通话和视频通话需要实时写入数据
                 # 正式服通过定时任务批量写入数据
-                if params['event_type'] in EventTypeEnumObj.DATA_PUSH_EVENT_TYPE_LIST.value or \
+                if params['event_type'] in DATA_PUSH_EVENT_TYPE_LIST or \
                         CONFIG_INFO == CONFIG_TEST:
                     end = 0
                     # 缓存数据多于100条,批量保存前100条,否则保存全部
@@ -478,7 +479,7 @@ class DevicePushService:
                         vsees_huawei_push_object = VseesHuaweiPushObject()
                         vsees_huawei_push_object.send_push_notify_message(**push_kwargs)
                 elif push_type == 4:  # android xmpush
-                    if kwargs['event_type'] in EventTypeEnumObj.DATA_PUSH_EVENT_TYPE_LIST.value:
+                    if kwargs['event_type'] in DATA_PUSH_EVENT_TYPE_LIST:
                         push_channel = 'push_to_talk'
                     else:
                         push_channel = 'device_reminder'
@@ -494,7 +495,7 @@ class DevicePushService:
                 elif push_type == 8:  # android honorpush
                     push_result = PushObject.android_honorpush(**push_kwargs)
 
-            if kwargs['event_type'] in EventTypeEnumObj.DATA_PUSH_EVENT_TYPE_LIST.value:
+            if kwargs['event_type'] in DATA_PUSH_EVENT_TYPE_LIST:
                 close_old_connections()
                 # 写入日志表
                 PushLog.objects.create(uid=uid, event_type=kwargs['event_type'], created_time=int(time.time()),
@@ -614,9 +615,9 @@ class DevicePushService:
                 if is_save_msg:
                     msg_type = 'SD卡异常,请重新插拔或格式化SD卡。如问题仍未解决,请联系在线客服。'
 
-            elif event_type in EventTypeEnumObj.DATA_PUSH_EVENT_TYPE_LIST.value:
+            elif event_type in DATA_PUSH_EVENT_TYPE_LIST:
                 msg_type = '有人呼叫,请点击查看'
-            if event_type not in EventTypeEnumObj.DATA_PUSH_EVENT_TYPE_LIST.value and ai_type > 0 and event_list:
+            if event_type not in DATA_PUSH_EVENT_TYPE_LIST 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:
@@ -678,9 +679,9 @@ class DevicePushService:
                     msg_type = 'SD card is abnormal, please re-insert or format the SD card. ' \
                                'If the problem is still not solved, please contact online customer service.'
 
-            elif event_type in EventTypeEnumObj.DATA_PUSH_EVENT_TYPE_LIST.value:
+            elif event_type in DATA_PUSH_EVENT_TYPE_LIST:
                 msg_type = 'Someone is calling, please click to view'
-            elif event_type not in EventTypeEnumObj.DATA_PUSH_EVENT_TYPE_LIST.value and ai_type > 0 and event_list:
+            elif event_type not in DATA_PUSH_EVENT_TYPE_LIST 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:
@@ -739,11 +740,11 @@ class DevicePushService:
                 else:
                     msg_type = MSG_CONFIG[706]['default'].get(lang, '')
 
-            elif event_type in EventTypeEnumObj.DATA_PUSH_EVENT_TYPE_LIST.value:
+            elif event_type in DATA_PUSH_EVENT_TYPE_LIST:
                 msg_type = MSG_CONFIG['data_push'].get(lang, '')
 
             # 组合事件处理文案
-            if event_type not in EventTypeEnumObj.DATA_PUSH_EVENT_TYPE_LIST.value and ai_type > 0 and event_list:
+            if event_type not in DATA_PUSH_EVENT_TYPE_LIST and ai_type > 0 and event_list:
                 msg_type = ''.join(
                     [DevicePushService.get_event_type_text_v2(lang, item, dealings_type) for item in event_list])
 
@@ -810,7 +811,7 @@ class DevicePushService:
                 'extra.channel': channel,
                 'extra.jump_type': jump_type
             }
-            if event_type in EventTypeEnumObj.DATA_PUSH_EVENT_TYPE_LIST.value:
+            if event_type in DATA_PUSH_EVENT_TYPE_LIST:
                 data['extra.sound_uri'] = 'android.resource://com.ansjer.zccloud_ab/raw/phone_call'
             headers = {
                 'Authorization': 'key={}'.format(app_secret)
@@ -835,7 +836,7 @@ class DevicePushService:
         android 国内oppo APP消息提醒推送
         """
         try:
-            if event_type in EventTypeEnumObj.DATA_PUSH_EVENT_TYPE_LIST.value:
+            if event_type in DATA_PUSH_EVENT_TYPE_LIST:
                 channel_id = XM_PUSH_CHANNEL_ID['push_to_talk']
             app_key = OPPOPUSH_CONFIG[appBundleId]['Key']
             master_secret = OPPOPUSH_CONFIG[appBundleId]['Secret']
@@ -883,7 +884,7 @@ class DevicePushService:
 
             response = requests.post(push_url, data=push_data, headers=headers)
             if response.status_code == 200:
-                if event_type in EventTypeEnumObj.DATA_PUSH_EVENT_TYPE_LIST.value:
+                if event_type in DATA_PUSH_EVENT_TYPE_LIST:
                     PushObject.jpush_transparent_transmission(msg_title, msg_text, appBundleId, jg_token_val,
                                                               extra_data)
                 return True

+ 2 - 2
Service/HuaweiPushService/HuaweiPushService.py

@@ -1,6 +1,6 @@
 import json
 
-from AnsjerPush.config import LOGGER
+from AnsjerPush.config import LOGGER, DATA_PUSH_EVENT_TYPE_LIST
 from Object.enums.EventTypeEnum import EventTypeEnumObj
 from Service.CommonService import CommonService
 from Service.HuaweiPushService import push_admin
@@ -43,7 +43,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 EventTypeEnumObj.DATA_PUSH_EVENT_TYPE_LIST.value:
+        if int(event_type) in DATA_PUSH_EVENT_TYPE_LIST:
             self.send_data_message(uid, event_type, n_time, token_val, channel)
 
         return send_succeed

+ 10 - 9
Service/PushService.py

@@ -19,7 +19,7 @@ from firebase_admin import messaging
 from pyfcm import FCMNotification
 
 from AnsjerPush.config import APP_BUNDLE_DICT, APNS_MODE, BASE_DIR, APNS_CONFIG, FCM_CONFIG, JPUSH_CONFIG, XMPUSH_CONFIG \
-    , VIVOPUSH_CONFIG, OPPOPUSH_CONFIG, MEIZUPUSH_CONFIG, CONFIG_INFO, HONORPUSH_CONFIG
+    , VIVOPUSH_CONFIG, OPPOPUSH_CONFIG, MEIZUPUSH_CONFIG, CONFIG_INFO, HONORPUSH_CONFIG, DATA_PUSH_EVENT_TYPE_LIST
 from Model.models import UidPushModel
 from Object.RedisObject import RedisObject
 from Object.S3Email import S3Email
@@ -133,7 +133,7 @@ class PushObject:
                          'received_at': n_time, 'event_time': n_time, 'event_type': event_type, 'nickname': nickname,
                          'image_url': launch_image, 'jump_type': jump_type
                          }
-            sound = 'call_phone.mp3' if event_type in EventTypeEnumObj.DATA_PUSH_EVENT_TYPE_LIST.value else 'default'
+            sound = 'call_phone.mp3' if event_type in DATA_PUSH_EVENT_TYPE_LIST 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)
@@ -168,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 EventTypeEnumObj.DATA_PUSH_EVENT_TYPE_LIST.value:
+            if event_type in DATA_PUSH_EVENT_TYPE_LIST:
                 push_data['priority'] = 'high'
                 push_data['content_available'] = True
                 push_data['direct_boot_ok'] = True
@@ -219,11 +219,12 @@ class PushObject:
             n_time = str(n_time)
             # 跳转类型
             jump_type = str(CommonService.get_jump_type(event_type))
+            # 推送数据类型必须为字符串,否则抛ValueError('Message.data must not contain non-string values.')异常
             push_data = {'alert': msg_text, 'msg': '', 'sound': 'sound.aif', 'zpush': '1',
                          'received_at': n_time, 'event_time': n_time, 'event_type': event_type, 'nickname': nickname,
                          'uid': uid, 'channel': channel, 'jump_type': jump_type
                          }
-            if event_type in EventTypeEnumObj.DATA_PUSH_EVENT_TYPE_LIST.value:
+            if event_type in DATA_PUSH_EVENT_TYPE_LIST:
                 push_data['priority'] = 'high'
                 push_data['content_available'] = True
                 push_data['direct_boot_ok'] = True
@@ -266,7 +267,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 EventTypeEnumObj.DATA_PUSH_EVENT_TYPE_LIST.value:
+            # if event_type in DATA_PUSH_EVENT_TYPE_LIST:
             #     channel_id = '111934'
             # else:
             #     channel_id = '1'
@@ -307,7 +308,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 EventTypeEnumObj.DATA_PUSH_EVENT_TYPE_LIST.value:
+            if event_type in DATA_PUSH_EVENT_TYPE_LIST:
                 channel_id = '111934'
             else:
                 channel_id = '1'
@@ -445,7 +446,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 EventTypeEnumObj.DATA_PUSH_EVENT_TYPE_LIST.value:
+            if rec['result'] == 0 and event_type in DATA_PUSH_EVENT_TYPE_LIST:
                 PushObject.jpush_transparent_transmission(msg_title, msg_text, app_bundle_id, jg_token_val, push_data)
             return True
         except Exception as e:
@@ -521,7 +522,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 EventTypeEnumObj.DATA_PUSH_EVENT_TYPE_LIST.value:
+            if response.status_code == 200 and event_type in DATA_PUSH_EVENT_TYPE_LIST:
                 PushObject.jpush_transparent_transmission(msg_title, msg_text, app_bundle_id, jg_token_val, extra_data)
             return True
         except Exception as e:
@@ -656,7 +657,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 EventTypeEnumObj.DATA_PUSH_EVENT_TYPE_LIST.value:
+            if int(event_type) in DATA_PUSH_EVENT_TYPE_LIST:
                 push_data = {
                     "data": json.dumps(extra_data),
                     "token": [token_val]

+ 2 - 2
Service/VSeesHuaweiPushService/VseesHuaweiPushObject.py

@@ -1,6 +1,6 @@
 import json
 
-from AnsjerPush.config import LOGGER
+from AnsjerPush.config import LOGGER, DATA_PUSH_EVENT_TYPE_LIST
 from Object.enums.EventTypeEnum import EventTypeEnumObj
 from Service.CommonService import CommonService
 from Service.VSeesHuaweiPushService import push_admin
@@ -43,7 +43,7 @@ class VseesHuaweiPushObject:
 
         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 EventTypeEnumObj.DATA_PUSH_EVENT_TYPE_LIST.value:
+        if int(event_type) in DATA_PUSH_EVENT_TYPE_LIST:
             self.send_data_message(uid, event_type, n_time, token_val, channel)
 
         return send_succeed