Browse Source

修改国内推送函数返回值为bool类型

locky 1 year ago
parent
commit
8c84f73a31
2 changed files with 26 additions and 22 deletions
  1. 3 3
      Service/HuaweiPushService/HuaweiPushService.py
  2. 23 19
      Service/PushService.py

+ 3 - 3
Service/HuaweiPushService/HuaweiPushService.py

@@ -18,7 +18,7 @@ class HuaweiPushObject:
         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='', nickname='', n_time='',
-                                 event_type='', channel='', app_bundle_id='', appBundleId=''):
+                                 event_type='0', channel='', app_bundle_id='', appBundleId=''):
         """
         发送推送消息
         @param token_val: 手机推送token
@@ -38,8 +38,8 @@ class HuaweiPushObject:
             '华为推送参数: uid:{}, token_val:{}, msg_title:{}, msg_text:{}, image_url:{}, event_type:{}, n_time:{}'.format(
                 uid, token_val, msg_title, msg_text, image_url, event_type, n_time))
 
-        send_succeed = self.send_notify_message(msg_title, msg_text, image_url, uid,
-                                               nickname, event_type, n_time, token_val)
+        send_succeed = self.send_notify_message(msg_title, msg_text, image_url, uid, nickname,
+                                                event_type, n_time, token_val)
         if int(event_type) in [606, 607]:
             self.send_data_message(uid, event_type, n_time, token_val)
 

+ 23 - 19
Service/PushService.py

@@ -189,7 +189,7 @@ class PushObject:
         @param msg_title: 推送标题
         @param msg_text: 推送内容
         @param channel: 设备通道
-        @return: None
+        @return: bool
         """
         try:
             app_key = JPUSH_CONFIG[app_bundle_id]['Key']
@@ -209,8 +209,10 @@ class PushObject:
             push.platform = jpush.all_
             res = push.send()
             assert res.status_code == 200
+            return True
         except Exception as e:
             LOGGER.info('极光推送异常:{}'.format(repr(e)))
+            return False
 
     @staticmethod
     def android_xmpush(channel_id, nickname, app_bundle_id, token_val, n_time, event_type, msg_title, msg_text,
@@ -228,9 +230,8 @@ class PushObject:
         @param uid: uid
         @param channel: 通道
         @param image: 推送图片链接
-        @return: None
+        @return: bool
         """
-        logger = logging.getLogger('info')
         try:
             url = 'https://api.xmpush.xiaomi.com/v3/message/regid'
             app_secret = XMPUSH_CONFIG[app_bundle_id]
@@ -263,10 +264,12 @@ class PushObject:
                 'Authorization': 'key={}'.format(app_secret)
             }
             response = requests.post(url, data=data, headers=headers)
-            logger.info("小米推送返回值:{}".format(response.json()))
+            LOGGER.info("小米推送返回值:{}".format(response.json()))
             assert response.status_code == 200
+            return True
         except Exception as e:
-            return repr(e)
+            LOGGER.info("小米推送异常:{}".format(repr(e)))
+            return False
 
     @staticmethod
     def android_vivopush(token_val, n_time, event_type, msg_title, msg_text, app_bundle_id='', uid='', channel='1',
@@ -285,9 +288,8 @@ class PushObject:
         @param uid: uid
         @param image: 推送图片链接
         @param channel: 通道
-        @return: None
+        @return: bool
         """
-        logger = logging.getLogger('info')
         try:
             app_bundle_id = app_bundle_id if app_bundle_id != '' else appBundleId
             # 获取redis里面的authToken
@@ -325,12 +327,13 @@ class PushObject:
                 .client_custom_map(**push_data) \
                 .message_dict()
             rec = sender_send.send(message)
-            logger.info('vivo推送结果:{}, 设备uid:{}'.format(rec, uid))
+            LOGGER.info('vivo推送结果:{}, 设备uid:{}'.format(rec, uid))
             if rec['result'] == 0 and event_type in [606, 607]:
                 PushObject.jpush_transparent_transmission(msg_title, msg_text, app_bundle_id, jg_token_val, push_data)
-            return rec
+            return True
         except Exception as e:
-            logger.info('vivo推送异常:{}'.format(e))
+            LOGGER.info('vivo推送异常:{}'.format(e))
+            return False
 
     @staticmethod
     def android_oppopush(channel_id, nickname, app_bundle_id, token_val, n_time, event_type, msg_title, msg_text,
@@ -349,9 +352,8 @@ class PushObject:
         @param uid: uid
         @param channel: 通道
         @param image: 推送图片链接
-        @return: None
+        @return: bool
         """
-        logger = logging.getLogger('info')
         try:
             """
             android 国内oppo APP消息提醒推送
@@ -400,11 +402,13 @@ class PushObject:
             }
 
             response = requests.post(push_url, data=push_data, headers=headers)
-            logger.info("oppo推送返回值:{}".format(response.json()))
+            LOGGER.info("oppo推送返回值:{}".format(response.json()))
             if response.status_code == 200 and event_type in [606, 607]:
                 PushObject.jpush_transparent_transmission(msg_title, msg_text, app_bundle_id, jg_token_val, extra_data)
+            return True
         except Exception as e:
-            return repr(e)
+            LOGGER.info("oppo推送异常:{}".format(repr(e)))
+            return False
 
     @staticmethod
     def android_meizupush(token_val, n_time, event_type, msg_title, msg_text, uid='', channel='1',
@@ -422,9 +426,8 @@ class PushObject:
         @param uid: uid
         @param image: 推送图片链接
         @param channel: 通道
-        @return: None
+        @return: bool
         """
-        logger = logging.getLogger('info')
         try:
             #  获取包和AppSecret
             app_bundle_id = app_bundle_id if app_bundle_id != '' else appBundleId
@@ -463,10 +466,11 @@ class PushObject:
             }
             # 进行推送
             response = requests.post(url, data=data)
-            logger.info("魅族推送结果:{}".format(response.json()))
-            return response.status_code
+            LOGGER.info("魅族推送结果:{}".format(response.json()))
+            return True
         except Exception as e:
-            return repr(e)
+            LOGGER.info("魅族推送异常:{}".format(repr(e)))
+            return False
 
     @staticmethod
     def jpush_transparent_transmission(msg_title, msg_text, app_bundle_id, token_val, extra_data):