Procházet zdrojové kódy

优化华为推送

peng před 11 měsíci
rodič
revize
01d806f9d6

+ 2 - 1
AnsjerPush/config.py

@@ -214,7 +214,8 @@ XM_PUSH_CHANNEL_ID = {
     'push_to_talk': 111934,        # 一键通话
     'device_reminder': 104551,     # 设备提醒
     'service_reminder': 104552,    # 服务提醒
-    'sys_notification': 104553     # 系统通知
+    'sys_notification': 104553,    # 系统通知
+    'single_login': 126707         # 单点登录
 }
 
 firebase_admin.initialize_app(credentials.Certificate(

+ 5 - 45
Controller/TransparentTransmissionPushController.py

@@ -10,6 +10,7 @@ from django.views import View
 
 from Model.models import UidPushModel, GatewayPush
 from Object.ResponseObject import ResponseObject
+from Service.HuaweiPushService.HuaweiPushService import HuaweiPushObject
 from Service.PushService import PushObject
 from AnsjerPush.config import XM_PUSH_CHANNEL_ID, HONORPUSH_CONFIG, LOGGER
 from Service.HuaweiPushService.push_admin import messaging
@@ -109,11 +110,12 @@ class TransparentTransmissionPushView(View):
                                                               push_item['token_val'], kwargs)
 
                 elif push_item['push_type'] == 3:  # 华为
-                    TransparentTransmissionPushView.huawei_transparent_transmission(user_id=user_id, **kwargs)
+                    huawei_push_object = HuaweiPushObject()
+                    huawei_push_object.huawei_transparent_transmission(user_id=user_id, **kwargs)
                 elif push_item['push_type'] == 4:  # 小米
                     channel_id = XM_PUSH_CHANNEL_ID['push_to_talk']
                     PushObject.android_xmpush(channel_id=channel_id, **kwargs)
-                elif push_item['push_type'] in [5, 6]:  # 小米, vivo, oppo
+                elif push_item['push_type'] in [5, 6]:  # vivo, oppo
                     kwargs['token_val'] = push_item['jg_token_val']
                     PushObject.jpush_transparent_transmission(title, content, push_item['app_bundle_id'],
                                                               push_item['jg_token_val'], kwargs)
@@ -125,49 +127,7 @@ class TransparentTransmissionPushView(View):
         except Exception as e:
             ERROR_INFO_LOGGER.info(
                 'TransparentTransmissionPushView推送线程异常:errLine:{}, errMsg:{}, 参数:{}'.format(
-                    e.__traceback__.tb_lineno,
-                    repr(e), push_list))
-
-    @staticmethod
-    def huawei_transparent_transmission(nickname, app_bundle_id, token_val, n_time, event_type, msg_title,
-                                        msg_text, user_id):
-        """
-        发送透传推送
-        @param nickname:
-        @param app_bundle_id:
-        @param event_type:
-        @param n_time:
-        @param token_val:
-        @param msg_title:
-        @param msg_text:
-        @param user_id:
-        @return: None
-        """
-        data = {
-            'nickname': nickname, 'event_type': event_type, 'event_time': n_time, 'msg_title': msg_title,
-            'msg_text': msg_text
-        }
-        data = json.dumps(data)
-        android = messaging.AndroidConfig(
-            collapse_key=-1,
-            urgency=messaging.AndroidConfig.HIGH_PRIORITY,
-            ttl='10000s',
-            bi_tag='the_sample_bi_tag_for_receipt_service'
-        )
-
-        message = messaging.Message(
-            data=data,
-            android=android,
-            token=[token_val]
-        )
-
-        try:
-            import certifi
-            response = messaging.send_message(message, verify_peer=certifi.where())
-            LOGGER.info('{}退出登录,华为透传推送响应: {}'.format(user_id, json.dumps(vars(response))))
-            assert (response.code == '80000000')
-        except Exception as e:
-            LOGGER.info('退出登录,华为透传推送异常: {}'.format(repr(e)))
+                    e.__traceback__.tb_lineno, repr(e), push_list))
 
     @staticmethod
     def honor_transparent_transmission(token_val, n_time, event_type, msg_title, msg_text, app_bundle_id, nickname=''):

+ 44 - 3
Service/HuaweiPushService/HuaweiPushService.py

@@ -71,9 +71,9 @@ class HuaweiPushObject:
 
         # 自定义键值对
         data = {
-                    'alert': 'Motion', 'msg': '', 'sound': 'sound.aif', 'zpush': '1', 'uid': uid, 'nickname': nickname,
-                    'event_type': event_type, 'received_at': n_time, 'event_time': n_time, 'channel': channel
-            }
+            'alert': 'Motion', 'msg': '', 'sound': 'sound.aif', 'zpush': '1', 'uid': uid, 'nickname': nickname,
+            'event_type': event_type, 'received_at': n_time, 'event_time': n_time, 'channel': channel
+        }
         data = json.dumps(data)
         # 推送通知内容配置
         intent = 'intent://com.vivo.pushvideo/detail?#Intent;scheme=vpushscheme;launchFlags=0x10000000;S.uid={};S.event_type={};S.event_time={};end'.format(
@@ -177,3 +177,44 @@ class HuaweiPushObject:
             #     {'name': '拒绝', 'action_type': 3}
             # ]
         )
+
+    @staticmethod
+    def huawei_transparent_transmission(nickname, app_bundle_id, token_val, n_time, event_type, msg_title,
+                                        msg_text, user_id):
+        """
+        发送透传推送
+        @param nickname:
+        @param app_bundle_id:
+        @param event_type:
+        @param n_time:
+        @param token_val:
+        @param msg_title:
+        @param msg_text:
+        @param user_id:
+        @return: None
+        """
+        data = {
+            'nickname': nickname, 'event_type': event_type, 'event_time': n_time, 'msg_title': msg_title,
+            'msg_text': msg_text
+        }
+        data = json.dumps(data)
+        android = messaging.AndroidConfig(
+            collapse_key=-1,
+            urgency=messaging.AndroidConfig.HIGH_PRIORITY,
+            ttl='10000s',
+            bi_tag='the_sample_bi_tag_for_receipt_service'
+        )
+
+        message = messaging.Message(
+            data=data,
+            android=android,
+            token=[token_val]
+        )
+
+        try:
+            import certifi
+            response = messaging.send_message(message, verify_peer=certifi.where())
+            LOGGER.info('{}退出登录,华为透传推送响应: {}'.format(user_id, json.dumps(vars(response))))
+            assert (response.code == '80000000')
+        except Exception as e:
+            LOGGER.info('{}退出登录,华为透传推送异常: {}'.format(user_id, repr(e)))