|
@@ -155,29 +155,10 @@ class DevicePushService:
|
|
|
params['app_push'], params['uid'])
|
|
|
|
|
|
for up in params['uid_set_push_list']:
|
|
|
- appBundleId = up['appBundleId']
|
|
|
- token_val = up['token_val']
|
|
|
lang = up['lang']
|
|
|
tz = up['tz']
|
|
|
if tz is None or tz == '':
|
|
|
tz = 0
|
|
|
- # 发送标题
|
|
|
- msg_title = cls.get_msg_title(nickname=params['nickname'])
|
|
|
- # 发送内容
|
|
|
- msg_text = cls.get_msg_text(channel=params['channel'], n_time=params['n_time'], lang=lang, tz=tz,
|
|
|
- event_type=params['event_type'], ai_type=params['ai_type'],
|
|
|
- device_type=params['device_type'], electricity=params['electricity'],
|
|
|
- dealings_type=params['dealings_type'], event_tag=params['event_tag']
|
|
|
- )
|
|
|
- kwag_args['appBundleId'] = appBundleId
|
|
|
- kwag_args['token_val'] = token_val
|
|
|
- kwag_args['msg_title'] = msg_title
|
|
|
- kwag_args['msg_text'] = msg_text
|
|
|
- if params['event_type'] in [606, 607] and up['push_type'] in [5, 6]:
|
|
|
- kwag_args['jg_token_val'] = up['jg_token_val']
|
|
|
- else:
|
|
|
- if 'jg_token_val' in kwag_args:
|
|
|
- kwag_args.pop('jg_token_val')
|
|
|
|
|
|
# 保存系统消息或推送消息数据
|
|
|
user_id = up['userID_id']
|
|
@@ -200,12 +181,35 @@ class DevicePushService:
|
|
|
|
|
|
# 推送
|
|
|
if is_app_push:
|
|
|
+ push_type = up['push_type']
|
|
|
+ if params['event_type'] in [606, 607] and push_type in [5, 6]:
|
|
|
+ kwag_args['jg_token_val'] = up['jg_token_val']
|
|
|
+ else:
|
|
|
+ if 'jg_token_val' in kwag_args:
|
|
|
+ kwag_args.pop('jg_token_val')
|
|
|
+
|
|
|
+ appBundleId = up['appBundleId']
|
|
|
+ token_val = up['token_val']
|
|
|
+ # 发送标题
|
|
|
+ msg_title = cls.get_msg_title(nickname=params['nickname'])
|
|
|
+ # 发送内容
|
|
|
+ msg_text = cls.get_msg_text(channel=params['channel'], n_time=params['n_time'], lang=lang, tz=tz,
|
|
|
+ event_type=params['event_type'], ai_type=params['ai_type'],
|
|
|
+ device_type=params['device_type'], electricity=params['electricity'],
|
|
|
+ dealings_type=params['dealings_type'], event_tag=params['event_tag']
|
|
|
+ )
|
|
|
+
|
|
|
+ kwag_args['appBundleId'] = appBundleId
|
|
|
+ kwag_args['token_val'] = token_val
|
|
|
+ kwag_args['msg_title'] = msg_title
|
|
|
+ kwag_args['msg_text'] = msg_text
|
|
|
+ params['kwag_args'] = kwag_args
|
|
|
params['appBundleId'] = appBundleId
|
|
|
params['token_val'] = token_val
|
|
|
params['lang'] = lang
|
|
|
params['tz'] = tz
|
|
|
- params['kwag_args'] = kwag_args
|
|
|
- cls.send_app_msg_push(up['push_type'], **params)
|
|
|
+
|
|
|
+ cls.send_app_msg_push(push_type, **params)
|
|
|
|
|
|
# 写入系统消息
|
|
|
if sys_msg_list:
|
|
@@ -274,71 +278,76 @@ class DevicePushService:
|
|
|
@classmethod
|
|
|
def send_app_msg_push(cls, push_type, **param):
|
|
|
"""
|
|
|
- 发送app消息推送
|
|
|
+ 发送推送
|
|
|
+ @param push_type: 推送类型
|
|
|
+ @return push_result: bool
|
|
|
"""
|
|
|
try:
|
|
|
kwargs = param['kwag_args']
|
|
|
- result = {'do_apns_code': '', 'do_fcm_code': '', 'do_jpush_code': '', 'do_xmpush_code': '',
|
|
|
- 'do_vivopush_code': '', 'do_meizupush_code': '', 'do_oppopush_code': ''}
|
|
|
- # 判断是否进行APP消息推送,如app_push不为空,则不进行推送
|
|
|
- if not param['app_push']:
|
|
|
- LOGGING.info('APP准备推送:{}, {}'.format(param['uid'], param))
|
|
|
-
|
|
|
- # is_st为1或3,且推送类型为apns,gcm,华为,异步推送图片
|
|
|
- if (param['is_st'] == 1 or param['is_st'] == 3) and \
|
|
|
- (push_type == 0 or push_type == 1 or push_type == 3):
|
|
|
- if param['is_st'] == 1:
|
|
|
- key = '{}/{}/{}.jpeg'.format(param['uid'], param['channel'], param['n_time'])
|
|
|
- else:
|
|
|
- key = '{}/{}/{}_0.jpeg'.format(param['uid'], param['channel'], param['n_time'])
|
|
|
- push_thread = threading.Thread(target=cls.async_send_picture_push, args=(
|
|
|
- push_type, param['aws_s3_client'], param['bucket'], key,
|
|
|
- param['uid'], param['appBundleId'], param['token_val'], param['event_type'], param['n_time'],
|
|
|
- param['kwag_args']['msg_title'], param['kwag_args']['msg_text'], param['channel']))
|
|
|
- push_thread.start()
|
|
|
- # 不推图
|
|
|
+ push_result = False
|
|
|
+
|
|
|
+ LOGGING.info('{}开始推送'.format(param['uid']))
|
|
|
+
|
|
|
+ # is_st为1或3,且推送类型为apns,gcm,华为,异步推送图片
|
|
|
+ if (param['is_st'] == 1 or param['is_st'] == 3) and \
|
|
|
+ (push_type == 0 or push_type == 1 or push_type == 3):
|
|
|
+ if param['is_st'] == 1:
|
|
|
+ key = '{}/{}/{}.jpeg'.format(param['uid'], param['channel'], param['n_time'])
|
|
|
else:
|
|
|
+ key = '{}/{}/{}_0.jpeg'.format(param['uid'], param['channel'], param['n_time'])
|
|
|
+ # 开始异步推送图片
|
|
|
+ push_thread = threading.Thread(target=cls.async_send_picture_push, args=(
|
|
|
+ push_type, param['aws_s3_client'], param['bucket'], key,
|
|
|
+ param['uid'], param['appBundleId'], param['token_val'], param['event_type'], param['n_time'],
|
|
|
+ param['kwag_args']['msg_title'], param['kwag_args']['msg_text'], param['channel']))
|
|
|
+ push_thread.start()
|
|
|
+ push_result = True
|
|
|
+
|
|
|
+ # 不推图
|
|
|
+ else:
|
|
|
+ if push_type in [0, 1, 2]:
|
|
|
+ push_kwargs = {
|
|
|
+ 'nickname': param['uid'],
|
|
|
+ 'app_bundle_id': param['appBundleId'],
|
|
|
+ 'token_val': param['token_val'],
|
|
|
+ 'n_time': param['n_time'],
|
|
|
+ 'event_type': param['event_type'],
|
|
|
+ 'msg_title': param['kwag_args']['msg_title'],
|
|
|
+ 'msg_text': param['kwag_args']['msg_text'],
|
|
|
+ 'uid': param['uid'],
|
|
|
+ 'channel': param['channel']
|
|
|
+ }
|
|
|
+
|
|
|
if push_type == 0: # ios apns
|
|
|
- result['do_apns_code'] = PushObject.ios_apns_push(param['uid'], param['appBundleId'],
|
|
|
- param['token_val'], param['n_time'],
|
|
|
- param['event_type'],
|
|
|
- param['kwag_args']['msg_title'],
|
|
|
- param['kwag_args']['msg_text'],
|
|
|
- param['uid'], param['channel'])
|
|
|
+ push_result = PushObject.ios_apns_push(**push_kwargs)
|
|
|
elif push_type == 1: # android gcm
|
|
|
- result['do_fcm_code'] = PushObject.android_fcm_push(param['uid'], param['appBundleId'],
|
|
|
- param['token_val'], param['n_time'],
|
|
|
- param['event_type'],
|
|
|
- param['kwag_args']['msg_title'],
|
|
|
- param['kwag_args']['msg_text'],
|
|
|
- param['uid'], param['channel'])
|
|
|
+ push_result = PushObject.android_fcm_push(**push_kwargs)
|
|
|
elif push_type == 2: # android jpush
|
|
|
- result['do_jpush_code'] = PushObject.android_jpush(param['uid'], param['appBundleId'],
|
|
|
- param['token_val'], param['n_time'],
|
|
|
- param['event_type'],
|
|
|
- param['kwag_args']['msg_title'],
|
|
|
- param['kwag_args']['msg_text'],
|
|
|
- param['channel'])
|
|
|
- elif push_type == 3:
|
|
|
- huawei_push_object = HuaweiPushObject()
|
|
|
- huawei_push_object.send_push_notify_message(**kwargs)
|
|
|
- elif push_type == 4: # android xmpush
|
|
|
- if param['event_type'] in [606, 607]:
|
|
|
- channel_id = 111934
|
|
|
- else:
|
|
|
- channel_id = 104551
|
|
|
- result['do_xmpush_code'] = cls.do_xmpush(channel_id=channel_id, **kwargs)
|
|
|
- elif push_type == 5: # android vivopush
|
|
|
- result['do_vivopush_code'] = PushObject.android_vivopush(**kwargs)
|
|
|
- elif push_type == 6: # android oppopush
|
|
|
- channel_id = 'DEVICE_REMINDER'
|
|
|
- result['do_oppopush_code'] = cls.do_oppopush(channel_id=channel_id, **kwargs)
|
|
|
- elif push_type == 7: # android meizupush
|
|
|
- result['do_meizupush_code'] = PushObject.android_meizupush(**kwargs)
|
|
|
- return result
|
|
|
+ push_kwargs.pop('uid')
|
|
|
+ push_result = PushObject.android_jpush(**push_kwargs)
|
|
|
+
|
|
|
+ elif push_type == 3:
|
|
|
+ huawei_push_object = HuaweiPushObject()
|
|
|
+ huawei_push_object.send_push_notify_message(**kwargs)
|
|
|
+ elif push_type == 4: # android xmpush
|
|
|
+ if param['event_type'] in [606, 607]:
|
|
|
+ channel_id = 111934
|
|
|
+ else:
|
|
|
+ channel_id = 104551
|
|
|
+ cls.do_xmpush(channel_id=channel_id, **kwargs)
|
|
|
+ push_result = True
|
|
|
+ elif push_type == 5: # android vivopush
|
|
|
+ push_result = PushObject.android_vivopush(**kwargs)
|
|
|
+ elif push_type == 6: # android oppopush
|
|
|
+ channel_id = 'DEVICE_REMINDER'
|
|
|
+ cls.do_oppopush(channel_id=channel_id, **kwargs)
|
|
|
+ push_result = True
|
|
|
+ elif push_type == 7: # android meizupush
|
|
|
+ push_result = PushObject.android_meizupush(**kwargs)
|
|
|
+ return push_result
|
|
|
except Exception as e:
|
|
|
- LOGGING.info('异常详情,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
- return None
|
|
|
+ LOGGING.info('发送推送异常,error_line:{},error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
+ return False
|
|
|
|
|
|
@classmethod
|
|
|
def created_device_vo(cls, local_date_time, **params):
|
|
@@ -621,26 +630,24 @@ class DevicePushService:
|
|
|
def async_send_picture_push(cls, push_type, aws_s3_client, bucket, key, uid, appBundleId,
|
|
|
token_val, event_type, n_time, msg_title, msg_text, channel):
|
|
|
"""
|
|
|
- 异步APP图片推送
|
|
|
+ 异步推送图片
|
|
|
"""
|
|
|
try:
|
|
|
- image_url = aws_s3_client.generate_presigned_url('get_object',
|
|
|
- Params={'Bucket': bucket, 'Key': key},
|
|
|
- ExpiresIn=3600)
|
|
|
- LOGGING.info('推送图片url:{}'.format(image_url))
|
|
|
+ image_url = aws_s3_client.generate_presigned_url(
|
|
|
+ 'get_object', Params={'Bucket': bucket, 'Key': key}, ExpiresIn=3600)
|
|
|
if push_type == 0:
|
|
|
- PushObject.ios_apns_push(uid, appBundleId, token_val, n_time, event_type, msg_title, msg_text,
|
|
|
- uid, channel, image_url)
|
|
|
+ PushObject.ios_apns_push(
|
|
|
+ uid, appBundleId, token_val, n_time, event_type, msg_title, msg_text, uid, channel, image_url)
|
|
|
elif push_type == 1:
|
|
|
- PushObject.android_fcm_push(uid, appBundleId, token_val, n_time, event_type, msg_title,
|
|
|
- msg_text, uid, channel, image_url)
|
|
|
+ PushObject.android_fcm_push(
|
|
|
+ uid, appBundleId, token_val, n_time, event_type, msg_title, msg_text, uid, channel, image_url)
|
|
|
elif push_type == 3:
|
|
|
huawei_push_object = HuaweiPushObject()
|
|
|
- huawei_push_object.send_push_notify_message(token_val=token_val, msg_title=msg_title, msg_text=msg_text,
|
|
|
- uid=uid, event_type=event_type, n_time=n_time,
|
|
|
- image_url=image_url)
|
|
|
+ huawei_push_object.send_push_notify_message(
|
|
|
+ token_val=token_val, msg_title=msg_title, msg_text=msg_text, uid=uid, event_type=event_type,
|
|
|
+ n_time=n_time, image_url=image_url)
|
|
|
except Exception as e:
|
|
|
- LOGGING.info('图片推送异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
+ LOGGING.info('异步推送图片异常,error_line:{},error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
|
|
|
@staticmethod
|
|
|
def get_push_url(**kwargs):
|