locky преди 2 години
родител
ревизия
4e39e88eff
променени са 1 файла, в които са добавени 61 реда и са изтрити 58 реда
  1. 61 58
      Service/HuaweiPushService/HuaweiPushService.py

+ 61 - 58
Service/HuaweiPushService/HuaweiPushService.py

@@ -55,66 +55,69 @@ class HuaweiPushObject:
         @param token_val:
         @return: None
         """
-        LOGGER.info('{}进入发送通知推送函数'.format(uid))
-        msg_title = '设备昵称: {}'.format(msg_title)
-        notification = messaging.Notification(
-            title=msg_title,
-            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
-                }
-        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_attributes = dir(android_notification)
-        for attr in android_notification_attributes:
-            if not attr.startswith('__') and not attr.endswith('__'):
-                value = getattr(android_notification, attr)
-                LOGGER.info('android_notification_attributes {}: {}'.format(attr, value))
-
-        # 安卓配置
-        android = messaging.AndroidConfig(
-            data=data,
-            collapse_key=-1,
-            urgency=messaging.AndroidConfig.NORMAL_PRIORITY,
-            ttl='10000s',
-            bi_tag='the_sample_bi_tag_for_receipt_service',
-            notification=android_notification,
-            category='DEVICE_REMINDER'
-        )
-
-        android_attributes = dir(android)
-        for attr in android_attributes:
-            if not attr.startswith('__') and not attr.endswith('__'):
-                value = getattr(android_attributes, attr)
-                LOGGER.info('android_attributes {}: {}'.format(attr, value))
-
-        message = messaging.Message(
-            notification=notification,
-            android=android,
-            token=[token_val]
-        )
-
-        message_attributes = dir(message)
-        for attr in message_attributes:
-            if not attr.startswith('__') and not attr.endswith('__'):
-                value = getattr(message_attributes, attr)
-                LOGGER.info('message_attributes {}: {}'.format(attr, value))
-
         try:
-            import certifi
-            response = messaging.send_message(message, verify_peer=certifi.where())
-            LOGGER.info('{}华为通知推送响应: {}'.format(uid, json.dumps(vars(response))))
-            assert (response.code == '80000000')
+            LOGGER.info('{}进入发送通知推送函数'.format(uid))
+            msg_title = '设备昵称: {}'.format(msg_title)
+            notification = messaging.Notification(
+                title=msg_title,
+                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
+                    }
+            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_attributes = dir(android_notification)
+            for attr in android_notification_attributes:
+                if not attr.startswith('__') and not attr.endswith('__'):
+                    value = getattr(android_notification, attr)
+                    LOGGER.info('android_notification_attributes {}: {}'.format(attr, value))
+
+            # 安卓配置
+            android = messaging.AndroidConfig(
+                data=data,
+                collapse_key=-1,
+                urgency=messaging.AndroidConfig.NORMAL_PRIORITY,
+                ttl='10000s',
+                bi_tag='the_sample_bi_tag_for_receipt_service',
+                notification=android_notification,
+                category='DEVICE_REMINDER'
+            )
+
+            android_attributes = dir(android)
+            for attr in android_attributes:
+                if not attr.startswith('__') and not attr.endswith('__'):
+                    value = getattr(android_attributes, attr)
+                    LOGGER.info('android_attributes {}: {}'.format(attr, value))
+
+            message = messaging.Message(
+                notification=notification,
+                android=android,
+                token=[token_val]
+            )
+
+            message_attributes = dir(message)
+            for attr in message_attributes:
+                if not attr.startswith('__') and not attr.endswith('__'):
+                    value = getattr(message_attributes, attr)
+                    LOGGER.info('message_attributes {}: {}'.format(attr, value))
+
+            try:
+                import certifi
+                response = messaging.send_message(message, verify_peer=certifi.where())
+                LOGGER.info('{}华为通知推送响应: {}'.format(uid, json.dumps(vars(response))))
+                assert (response.code == '80000000')
+            except Exception as e:
+                LOGGER.info('华为通知推送异常: {}'.format(repr(e)))
         except Exception as e:
-            LOGGER.info('华为通知推送异常: {}'.format(repr(e)))
+            LOGGER.info('华为通知推送异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
 
     @staticmethod
     def send_data_message(uid, event_type, n_time, token_val):