|
@@ -157,7 +157,7 @@ class DevicePushService:
|
|
|
|
|
|
# 低功耗产品推送,休眠702、低电量704提醒,并且detection=0,0标识单事件类型,1标识多事件类型
|
|
|
is_app_push = True if params['event_type'] in [702, 704] and params['detection'] == 0 else is_app_push
|
|
|
-
|
|
|
+ redis_obj = RedisObject(3)
|
|
|
# 推送
|
|
|
if is_app_push:
|
|
|
push_kwargs = params['push_kwargs']
|
|
@@ -195,6 +195,7 @@ class DevicePushService:
|
|
|
params['lang'] = lang
|
|
|
params['tz'] = tz
|
|
|
params['push_type'] = push_type
|
|
|
+ params['redis_obj'] = redis_obj
|
|
|
|
|
|
push_thread = threading.Thread(
|
|
|
target=cls.send_app_msg_push,
|
|
@@ -374,7 +375,8 @@ class DevicePushService:
|
|
|
push_thread = threading.Thread(target=cls.async_send_picture_push, args=(
|
|
|
push_type, kwargs['aws_s3_client'], kwargs['bucket'], key,
|
|
|
kwargs['uid'], kwargs['appBundleId'], kwargs['token_val'], kwargs['event_type'], kwargs['n_time'],
|
|
|
- push_kwargs['msg_title'], push_kwargs['msg_text'], kwargs['channel'], kwargs['storage_location']))
|
|
|
+ push_kwargs['msg_title'], push_kwargs['msg_text'], kwargs['channel'], kwargs['storage_location'],
|
|
|
+ kwargs['redis_obj']))
|
|
|
push_thread.start()
|
|
|
push_result = True
|
|
|
|
|
@@ -687,14 +689,14 @@ class DevicePushService:
|
|
|
return response.json()
|
|
|
|
|
|
@classmethod
|
|
|
- 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, storage_reg):
|
|
|
+ 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, storage_reg, redis_obj):
|
|
|
"""
|
|
|
异步推送图片
|
|
|
"""
|
|
|
try:
|
|
|
if storage_reg in [3, 4]:
|
|
|
- image_url = DevicePushService.oci_object_url(storage_reg, bucket, key)
|
|
|
+ image_url = DevicePushService.oci_object_url(uid, redis_obj, storage_reg, bucket, key)
|
|
|
else:
|
|
|
image_url = aws_s3_client.generate_presigned_url(
|
|
|
'get_object', Params={'Bucket': bucket, 'Key': key}, ExpiresIn=3600)
|
|
@@ -716,18 +718,32 @@ class DevicePushService:
|
|
|
LOGGING.error('异步推送图片异常,error_line:{},error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
|
|
|
@staticmethod
|
|
|
- def oci_object_url(storage_location, bucket, obj_name):
|
|
|
+ def oci_object_url(uid, redis_obj, storage_location, bucket, obj_name):
|
|
|
"""
|
|
|
获取OCI对象存储URL 有效期5分钟
|
|
|
+ @param uid: uid
|
|
|
+ @param redis_obj: 缓存客户端
|
|
|
@param storage_location: 存储区域
|
|
|
@param bucket: 存储桶
|
|
|
@param obj_name: 对象名称
|
|
|
@return: url
|
|
|
"""
|
|
|
- oci = OCIObjectStorage('eur' if storage_location == 4 else 'us')
|
|
|
- time_expires = datetime.datetime.utcnow() + datetime.timedelta(minutes=60)
|
|
|
- result = oci.get_preauthenticated_request_url(bucket, 'ociPush', obj_name, time_expires)
|
|
|
- return result.full_path if result else ''
|
|
|
+ try:
|
|
|
+ uid_key = f'PUSH:PICTURE:OCI:URL:{uid}'
|
|
|
+ oci_url = redis_obj.get_data(uid_key)
|
|
|
+ if oci_url:
|
|
|
+ return oci_url + obj_name
|
|
|
+ oci = OCIObjectStorage('eur' if storage_location == 4 else 'us')
|
|
|
+ prefix_name = f'{uid}/'
|
|
|
+ time_expires = datetime.datetime.utcnow() + datetime.timedelta(minutes=60)
|
|
|
+ result = oci.get_preauthenticated_request_url(bucket, 'ociPush', prefix_name, time_expires,
|
|
|
+ 'AnyObjectRead') # 授权到指定uid文件夹
|
|
|
+ full_url = result.full_path if result else ''
|
|
|
+ redis_obj.set_data(uid_key, full_url, 3580)
|
|
|
+ return full_url + obj_name
|
|
|
+ except Exception as e:
|
|
|
+ LOGGING.error('oci查询消息列表异常error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
+ return ''
|
|
|
|
|
|
@staticmethod
|
|
|
def create_oci_req_url(storage_location, bucket, obj_name, oci=None):
|