|
@@ -44,7 +44,7 @@ class NotificationV2View(View):
|
|
|
@param request_dict:electricity 电量值
|
|
|
"""
|
|
|
logger = logging.getLogger('info')
|
|
|
- logger.info("移动侦测V2接口参数:{}".format(request_dict))
|
|
|
+ logger.info('移动侦测V2接口参数:{}'.format(request_dict))
|
|
|
uidToken = request_dict.get('uidToken', None)
|
|
|
etk = request_dict.get('etk', None)
|
|
|
channel = request_dict.get('channel', '1')
|
|
@@ -53,6 +53,8 @@ class NotificationV2View(View):
|
|
|
is_st = request_dict.get('is_st', None)
|
|
|
region = request_dict.get('region', None)
|
|
|
electricity = request_dict.get('electricity', '')
|
|
|
+ time_token = request_dict.get('time_token', None)
|
|
|
+ uid = request_dict.get('uid', None)
|
|
|
|
|
|
if not all([channel, n_time]):
|
|
|
return JsonResponse(status=200, data={
|
|
@@ -60,71 +62,77 @@ class NotificationV2View(View):
|
|
|
'msg': 'param is wrong'})
|
|
|
if not region or not is_st:
|
|
|
return JsonResponse(status=200, data={'code': 404, 'msg': 'no region or is_st'})
|
|
|
-
|
|
|
+ # 时间戳token校验
|
|
|
+ if time_token:
|
|
|
+ if not CommonService.check_time_stamp_token(time_token, n_time):
|
|
|
+ return JsonResponse(status=200, data={'code': 13, 'msg': 'Timestamp token verification failed'})
|
|
|
try:
|
|
|
- with transaction.atomic():
|
|
|
- is_st = int(is_st)
|
|
|
- region = int(region)
|
|
|
+ is_st = int(is_st)
|
|
|
+ region = int(region)
|
|
|
+ event_type = int(event_type)
|
|
|
+ if not uid:
|
|
|
uid = DevicePushService.decode_uid(etk, uidToken) # 解密uid
|
|
|
- if len(uid) != 20 and len(uid) != 14:
|
|
|
- return JsonResponse(status=200, data={'code': 404, 'msg': 'wrong uid'})
|
|
|
- req_limiting = '{uid}_{channel}_{event_type}_ptl' \
|
|
|
+ if len(uid) != 20 and len(uid) != 14:
|
|
|
+ return JsonResponse(status=200, data={'code': 404, 'msg': 'wrong uid'})
|
|
|
+ req_limiting = '{uid}_{channel}_{event_type}_ptl' \
|
|
|
+ .format(uid=uid, channel=channel, event_type=event_type)
|
|
|
+ is_sys_msg = self.is_sys_msg(int(event_type)) # 判断事件类型是否是系统消息
|
|
|
+ if is_sys_msg:
|
|
|
+ push_interval = '{uid}_{channel}_{event_type}_flag' \
|
|
|
.format(uid=uid, channel=channel, event_type=event_type)
|
|
|
- is_sys_msg = self.is_sys_msg(int(event_type)) # 判断事件类型是否是系统消息
|
|
|
- if is_sys_msg:
|
|
|
- push_interval = '{uid}_{channel}_{event_type}_flag' \
|
|
|
- .format(uid=uid, channel=channel, event_type=event_type)
|
|
|
- else:
|
|
|
- push_interval = '{uid}_{channel}_flag'.format(uid=uid, channel=channel)
|
|
|
- redisObj = RedisObject(db=6)
|
|
|
- cache_req_limiting = redisObj.get_data(key=req_limiting) # 获取请求限流缓存数据
|
|
|
- cache_app_push = redisObj.get_data(key=push_interval) # 获取APP推送消息时间间隔缓存数据
|
|
|
- logger.info('消息推送- 限流key: {}, 推送间隔key: {}'.
|
|
|
- format(cache_req_limiting, cache_app_push))
|
|
|
+ else:
|
|
|
+ push_interval = '{uid}_{channel}_flag'.format(uid=uid, channel=channel)
|
|
|
+ redisObj = RedisObject(db=6)
|
|
|
+ cache_req_limiting = redisObj.get_data(key=req_limiting) # 获取请求限流缓存数据
|
|
|
+ cache_app_push = redisObj.get_data(key=push_interval) # 获取APP推送消息时间间隔缓存数据
|
|
|
+ logger.info('消息推送- 限流key: {}, 推送间隔key: {}'.
|
|
|
+ format(cache_req_limiting, cache_app_push))
|
|
|
+ if event_type != 606:
|
|
|
if cache_req_limiting: # 限流存在则直接返回
|
|
|
return JsonResponse(status=200, data={'code': 0, 'msg': 'Push again in one minute'})
|
|
|
- redisObj.set_data(key=req_limiting, val=1, expire=60) # 当缓存不存在限流数据 重新设置一分钟请求一次
|
|
|
- uid_push_qs = DevicePushService.query_uid_push(uid) # 查询uid_set与push数据列表
|
|
|
- if not uid_push_qs.exists():
|
|
|
- logger.info('消息推送-uid_push 数据不存在')
|
|
|
- return JsonResponse(status=200, data={'code': 176, 'msg': 'no uid_push data'})
|
|
|
- ai_type = uid_push_qs.first()['uid_set__ai_type']
|
|
|
- event_type = self.get_combo_msg_type(ai_type, int(event_type)) # 解析消息事件类型看是否多类型组合
|
|
|
- # 将uid_set以及uid_push 转数组列表
|
|
|
- uid_set_push_list = DevicePushService.cache_uid_push(uid_push_qs)
|
|
|
- nickname = uid_set_push_list[0]['uid_set__nickname']
|
|
|
- nickname = uid if not nickname else nickname
|
|
|
- # APP消息提醒推送间隔
|
|
|
- detect_interval = uid_set_push_list[0]['uid_set__detect_interval']
|
|
|
+ redisObj.set_data(key=req_limiting, val=1, expire=60) # 当缓存不存在限流数据 重新设置一分钟请求一次
|
|
|
+ uid_push_qs = DevicePushService.query_uid_push(uid, event_type) # 查询uid_set与push数据列表
|
|
|
+ if not uid_push_qs.exists():
|
|
|
+ logger.info('消息推送-uid_push 数据不存在')
|
|
|
+ return JsonResponse(status=200, data={'code': 176, 'msg': 'no uid_push data'})
|
|
|
+ ai_type = uid_push_qs.first()['uid_set__ai_type']
|
|
|
+ event_type = self.get_combo_msg_type(ai_type, event_type) # 解析消息事件类型看是否多类型组合
|
|
|
+ # 将uid_set以及uid_push 转数组列表
|
|
|
+ uid_set_push_list = DevicePushService.cache_uid_push(uid_push_qs)
|
|
|
+ nickname = uid_set_push_list[0]['uid_set__nickname']
|
|
|
+ nickname = uid if not nickname else nickname
|
|
|
+ # APP消息提醒推送间隔
|
|
|
+ detect_interval = uid_set_push_list[0]['uid_set__detect_interval']
|
|
|
+ if event_type != 606:
|
|
|
if not cache_app_push:
|
|
|
# 缓存APP提醒推送间隔 默认1分钟提醒一次
|
|
|
DevicePushService.cache_push_detect_interval(redisObj, push_interval, detect_interval,
|
|
|
uid_set_push_list[0]['uid_set__new_detect_interval'])
|
|
|
- bucket = ''
|
|
|
- aws_s3_client = ''
|
|
|
- if is_st == 1 or is_st == 3: # 使用aws s3
|
|
|
- aws_s3_client = s3_client(region=region)
|
|
|
- bucket = 'foreignpush' if region == 1 else 'push'
|
|
|
- kwag_args = {
|
|
|
- 'uid': uid,
|
|
|
- 'channel': channel,
|
|
|
- 'event_type': event_type,
|
|
|
- 'n_time': n_time,
|
|
|
- }
|
|
|
- params = {'nickname': nickname, 'uid': uid, 'kwag_args': kwag_args, 'is_st': is_st, 'region': region,
|
|
|
- 'is_sys_msg': is_sys_msg, 'channel': channel, 'event_type': event_type, 'n_time': n_time,
|
|
|
- 'electricity': electricity, 'bucket': bucket, 'aws_s3_client': aws_s3_client,
|
|
|
- 'app_push': cache_app_push, 'storage_location': 2}
|
|
|
- # APP消息推送与获取报警消息数据列表
|
|
|
- result = DevicePushService.save_msg_push(uid_set_push_list, **params)
|
|
|
- # 批量系统消息&报警消息数据存库
|
|
|
- DevicePushService.save_sys_msg(is_sys_msg, result['local_date_time'],
|
|
|
- result['sys_msg_list'], result['new_device_info_list'])
|
|
|
- params['aws_s3_client'] = aws_s3_client
|
|
|
- params['uid_set_push_list'] = uid_set_push_list
|
|
|
- params['code_dict'] = result
|
|
|
- result_dict = DevicePushService.get_push_url(**params) # 获取S3对象上传链接
|
|
|
- return JsonResponse(status=200, data=result_dict)
|
|
|
+ bucket = ''
|
|
|
+ aws_s3_client = ''
|
|
|
+ if is_st == 1 or is_st == 3: # 使用aws s3
|
|
|
+ aws_s3_client = s3_client(region=region)
|
|
|
+ bucket = 'foreignpush' if region == 1 else 'push'
|
|
|
+ kwag_args = {
|
|
|
+ 'uid': uid,
|
|
|
+ 'channel': channel,
|
|
|
+ 'event_type': event_type,
|
|
|
+ 'n_time': n_time,
|
|
|
+ }
|
|
|
+ params = {'nickname': nickname, 'uid': uid, 'kwag_args': kwag_args, 'is_st': is_st, 'region': region,
|
|
|
+ 'is_sys_msg': is_sys_msg, 'channel': channel, 'event_type': event_type, 'n_time': n_time,
|
|
|
+ 'electricity': electricity, 'bucket': bucket, 'aws_s3_client': aws_s3_client,
|
|
|
+ 'app_push': cache_app_push, 'storage_location': 2}
|
|
|
+ # APP消息推送与获取报警消息数据列表
|
|
|
+ result = DevicePushService.save_msg_push(uid_set_push_list, **params)
|
|
|
+ # 批量系统消息&报警消息数据存库
|
|
|
+ DevicePushService.save_sys_msg(is_sys_msg, result['local_date_time'],
|
|
|
+ result['sys_msg_list'], result['new_device_info_list'])
|
|
|
+ params['aws_s3_client'] = aws_s3_client
|
|
|
+ params['uid_set_push_list'] = uid_set_push_list
|
|
|
+ params['code_dict'] = result
|
|
|
+ result_dict = DevicePushService.get_push_url(**params) # 获取S3对象上传链接
|
|
|
+ return JsonResponse(status=200, data=result_dict)
|
|
|
except Exception as e:
|
|
|
logger.info('消息推送-异常详情,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
data = {
|