소스 검색

华为发送推送增加自定义键值对

locky 2 년 전
부모
커밋
7cd5f6b2ca
1개의 변경된 파일10개의 추가작업 그리고 3개의 파일을 삭제
  1. 10 3
      Service/HuaweiPushService/HuaweiPushService.py

+ 10 - 3
Service/HuaweiPushService/HuaweiPushService.py

@@ -17,8 +17,8 @@ class HuaweiPushObject:
         """init sdk app"""
         push_admin.initialize_app(self.app_id, self.app_secret)
 
-    def send_push_notify_message(self, token_val, msg_title, msg_text, image_url=None, uid='', channel='', n_time='',
-                                 event_type='', app_bundle_id='', appBundleId=''):
+    def send_push_notify_message(self, token_val, msg_title, msg_text, image_url=None, uid='', nickname='', channel='',
+                                 n_time='', event_type='', app_bundle_id='', appBundleId=''):
         """
         发送推送消息
         @param token_val: 手机推送token
@@ -43,10 +43,17 @@ class HuaweiPushObject:
             body=msg_text,
             image=image_url
         )
+
+        # 自定义键值对
+        data = {'alert': 'Motion', 'msg': '', 'sound': 'sound.aif', 'zpush': '1',
+                'received_at': n_time, 'event_time': n_time, 'event_type': event_type, 'nickname': nickname
+                }
+        data = json.dumps(data)
         # 推送通知内容配置
         android_notification = self.android_notification(msg_title, msg_text)
         # 安卓配置
         android = messaging.AndroidConfig(
+            data=data,
             collapse_key=-1,
             urgency=messaging.AndroidConfig.NORMAL_PRIORITY,
             ttl='10000s',
@@ -101,5 +108,5 @@ class HuaweiPushObject:
             badge=messaging.AndroidBadgeNotification(
                 add_num=1, clazz='Classic'),
             visibility=messaging.AndroidNotification.PUBLIC,
-            foreground_show=True
+            foreground_show=False
         )