浏览代码

补齐推送类型

locky 1 年之前
父节点
当前提交
1be9942984
共有 1 个文件被更改,包括 48 次插入19 次删除
  1. 48 19
      Service/CustomizedPushService.py

+ 48 - 19
Service/CustomizedPushService.py

@@ -90,25 +90,8 @@ class CustomizedPushObject:
             user_id = gateway_push['user_id']
             app_bundle_id = gateway_push['app_bundle_id']
             token_val = gateway_push['token_val']
-            push_succeed = False
-            # ios
-            if push_type == 0:
-                push_succeed = PushObject.ios_apns_push(nickname='', app_bundle_id=app_bundle_id, token_val=token_val,
-                                                        n_time=n_time, event_type=0, msg_title=title, msg_text=msg,
-                                                        launch_image=icon_link)
-            # gcm
-            elif push_type == 1:
-                if icon_link is None:
-                    icon_link = ''
-                push_succeed = PushObject.android_fcm_push(
-                    nickname='', app_bundle_id=app_bundle_id, token_val=token_val, n_time=n_time, event_type=0,
-                    msg_title=title, msg_text=msg, image=icon_link)
-            # 华为
-            elif push_type == 3:
-                huawei_push_object = HuaweiPushObject()
-                push_succeed = huawei_push_object.send_push_notify_message(
-                    token_val=token_val, msg_title=title, msg_text=msg, n_time=n_time, event_type=0, image_url=icon_link
-                )
+
+            push_succeed = cls.push_msg(push_type, app_bundle_id, token_val, n_time, title, msg, icon_link)
 
             # 推送成功,写入系统消息
             if push_succeed:
@@ -122,3 +105,49 @@ class CustomizedPushObject:
                 CUSTOMIZED_PUSH_LOGGER.info('用户{}推送失败,push_type:{}'.format(user_id, push_type))
 
         CUSTOMIZED_PUSH_LOGGER.info('customized_push_id:{}推送完成'.format(kwargs['id']))
+
+    @staticmethod
+    def push_msg(push_type, app_bundle_id, token_val, n_time, title, msg, icon_link):
+        push_kwargs = {
+            'nickname': '',
+            'event_type': 0,
+            'app_bundle_id': app_bundle_id,
+            'token_val': token_val,
+            'msg_title': title,
+            'msg_text': msg,
+            'n_time': n_time,
+        }
+        # ios
+        if push_type == 0:
+            push_kwargs['launch_image'] = icon_link
+            return PushObject.ios_apns_push(**push_kwargs)
+        # gcm
+        elif push_type == 1:
+            if icon_link is None:
+                icon_link = ''
+            push_kwargs['image'] = icon_link
+            return PushObject.android_fcm_push(**push_kwargs)
+        # 极光
+        elif push_type == 2:
+            push_succeed = PushObject.android_jpush(**push_kwargs)
+        # 华为
+        elif push_type == 3:
+            push_kwargs['image_url'] = icon_link
+            huawei_push_object = HuaweiPushObject()
+            return huawei_push_object.send_push_notify_message(**push_kwargs)
+        # 小米
+        elif push_type == 4:
+            push_kwargs['channel_id'] = 104551
+            return PushObject.android_xmpush(**push_kwargs)
+        # vivo
+        elif push_type == 5:
+            return PushObject.android_vivopush(**push_kwargs)
+        # oppo
+        elif push_type == 6:
+            push_kwargs['channel_id'] = 'VALUE_ADDED'
+            return PushObject.android_oppopush(**push_kwargs)
+        # 魅族
+        elif push_type == 7:
+            return PushObject.android_meizupush(**push_kwargs)
+        else:
+            return False