Forráskód Böngészése

更新华为发送推送测试服代码

locky 2 éve
szülő
commit
f59dfd5c2d
1 módosított fájl, 18 hozzáadás és 10 törlés
  1. 18 10
      Service/HuaweiPushService/HuaweiPushService.py

+ 18 - 10
Service/HuaweiPushService/HuaweiPushService.py

@@ -17,21 +17,21 @@ 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='', n_time='',
+                                 event_type='', channel='', app_bundle_id='', appBundleId=''):
         """
         发送推送消息
         @param token_val: 手机推送token
         @param msg_title: 标题
         @param msg_text: 内容
-        @param n_time: 不使用
-        @param event_type: 不使用
-        @param app_bundle_id: 不使用
-        @param appBundleId: 不使用
-        @param uid: 不使用
-        @param channel: 不使用
-        @param msg_text: 不使用
         @param image_url: 图片链接
+        @param uid: uid
+        @param nickname: 设备昵称
+        @param n_time: 当前时间
+        @param event_type: 事件类型
+        @param channel: 通道
+        @param app_bundle_id: APP包id
+        @param appBundleId: APP包id
         @return:
         """
         logger = logging.getLogger('info')
@@ -43,10 +43,18 @@ class HuaweiPushObject:
             body=msg_text,
             image=image_url
         )
+
+        # 自定义键值对
+        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,
+                'action': 'com.ansjer.zccloud_a.AJ_MainView.AJ_Home.AJMainActivity'
+                }
+        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 +109,5 @@ class HuaweiPushObject:
             badge=messaging.AndroidBadgeNotification(
                 add_num=1, clazz='Classic'),
             visibility=messaging.AndroidNotification.PUBLIC,
-            foreground_show=True
+            foreground_show=False
         )