瀏覽代碼

华为推送一键通话和视频通话使用自定义铃声

locky 1 年之前
父節點
當前提交
634c50c31b

+ 19 - 5
Service/HuaweiPushService/HuaweiPushService.py

@@ -67,11 +67,18 @@ 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
                 }
+
+        # 一键通话和视频通话使用自定义铃声
+        if int(event_type) in [606, 607]:
+            category = 'VOIP'
+        else:
+            category = 'DEVICE_REMINDER'
+
         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(
             uid, event_type, n_time)
-        android_notification = self.android_notification(msg_title, msg_text, intent)
+        android_notification = self.android_notification(event_type, msg_title, msg_text, intent)
         # 安卓配置
         android = messaging.AndroidConfig(
             data=data,
@@ -80,7 +87,7 @@ class HuaweiPushObject:
             ttl='10000s',
             bi_tag='the_sample_bi_tag_for_receipt_service',
             notification=android_notification,
-            category='DEVICE_REMINDER'
+            category=category
         )
 
         message = messaging.Message(
@@ -132,12 +139,19 @@ class HuaweiPushObject:
             LOGGER.info('华为透传推送异常: {}'.format(repr(e)))
 
     @staticmethod
-    def android_notification(msg_title, msg_text, intent):
+    def android_notification(event_type, msg_title, msg_text, intent):
+        # 一键通话和视频通话使用自定义铃声
+        if int(event_type) in [606, 607]:
+            sound = '/raw/phone_call'
+            default_sound = False
+        else:
+            sound = '/raw/shake'
+            default_sound = True
         return messaging.AndroidNotification(
             icon='/raw/ic_launcher2',
             color='#AACCDD',
-            sound='/raw/shake',
-            default_sound=True,
+            sound=sound,
+            default_sound=default_sound,
             click_action=messaging.AndroidClickAction(
                 action_type=1,
                 intent=intent

+ 2 - 1
Service/HuaweiPushService/push_admin/_message_serializer.py

@@ -214,7 +214,8 @@ class MessageSerializer(json.JSONEncoder):
             "visibility": notification.visibility,
             "vibrate_config": notification.vibrate_config,
             "light_settings": MessageSerializer.encode_android_light_settings(notification.light_settings),
-            "foreground_show": notification.foreground_show
+            "foreground_show": notification.foreground_show,
+            "buttons": notification.buttons
         }
         result = cls.remove_null_values(result)
         return result

+ 3 - 1
Service/HuaweiPushService/push_admin/_messages.py

@@ -319,7 +319,8 @@ class AndroidNotification(object):
                  title_loc_args=None, multi_lang_key=None, channel_id=None, notify_summary=None, image=None,
                  style=None, big_title=None, big_body=None, auto_clear=None, notify_id=None, group=None, badge=None,
                  ticker=None, auto_cancel=None, when=None, importance=None, use_default_vibrate=True,
-                 use_default_light=True, vibrate_config=None, visibility=None, light_settings=None, foreground_show=False):
+                 use_default_light=True, vibrate_config=None, visibility=None, light_settings=None, foreground_show=False,
+                 buttons=None):
 
         MessageValidator.check_android(title=title, body=body, icon=icon, color=color, sound=sound,
                                        default_sound=default_sound, tag=tag, click_action=click_action,
@@ -368,6 +369,7 @@ class AndroidNotification(object):
         self.visibility = visibility
         self.light_settings = light_settings
         self.foreground_show = foreground_show
+        self.buttons = buttons
 
 
 class AndroidClickAction(object):