|
@@ -55,78 +55,48 @@ class HuaweiPushObject:
|
|
|
@param token_val:
|
|
|
@return: None
|
|
|
"""
|
|
|
- try:
|
|
|
- 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('__'):
|
|
|
- try:
|
|
|
- value = getattr(android_notification, attr)
|
|
|
- LOGGER.info('android_notification_attributes {}: {}'.format(attr, value))
|
|
|
- except Exception as e:
|
|
|
- continue
|
|
|
-
|
|
|
- # 安卓配置
|
|
|
- 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('__'):
|
|
|
- try:
|
|
|
- value = getattr(android_attributes, attr)
|
|
|
- LOGGER.info('android_attributes {}: {}'.format(attr, value))
|
|
|
- except Exception as e:
|
|
|
- continue
|
|
|
+ LOGGER.info('{}进入发送通知推送函数'.format(uid))
|
|
|
+ msg_title = '设备昵称: {}'.format(msg_title)
|
|
|
+ notification = messaging.Notification(
|
|
|
+ title=msg_title,
|
|
|
+ body=msg_text,
|
|
|
+ image=image_url
|
|
|
+ )
|
|
|
|
|
|
- message = messaging.Message(
|
|
|
- notification=notification,
|
|
|
- android=android,
|
|
|
- token=[token_val]
|
|
|
- )
|
|
|
+ # 自定义键值对
|
|
|
+ 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 = 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'
|
|
|
+ )
|
|
|
|
|
|
- message_attributes = dir(message)
|
|
|
- for attr in message_attributes:
|
|
|
- if not attr.startswith('__') and not attr.endswith('__'):
|
|
|
- try:
|
|
|
- value = getattr(message_attributes, attr)
|
|
|
- LOGGER.info('message_attributes {}: {}'.format(attr, value))
|
|
|
- except Exception as e:
|
|
|
- continue
|
|
|
+ message = messaging.Message(
|
|
|
+ notification=notification,
|
|
|
+ android=android,
|
|
|
+ token=[token_val]
|
|
|
+ )
|
|
|
+ LOGGER.info('通知栏推送category:{}'.format(message.android.category))
|
|
|
|
|
|
- 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)))
|
|
|
+ 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('华为通知推送异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
+ LOGGER.info('华为通知推送异常: {}'.format(repr(e)))
|
|
|
|
|
|
@staticmethod
|
|
|
def send_data_message(uid, event_type, n_time, token_val):
|