|
@@ -41,6 +41,10 @@ class NotificationV2View(View):
|
|
|
@param request_dict:is_st 文件类型(0:无,1:图片,2:视频)
|
|
|
@param request_dict:region 文件存储区域(1:国外,2国内)
|
|
|
@param request_dict:electricity 电量值
|
|
|
+ @param request_dict:time_token 时间戳token
|
|
|
+ @param request_dict:uid uid
|
|
|
+ @param request_dict:dealings_type 往来检测 1:来,2:离开
|
|
|
+ @param request_dict:detection 检测类型 0:普通,1:算法
|
|
|
"""
|
|
|
logger = logging.getLogger('info')
|
|
|
logger.info('移动侦测V2接口参数:{}'.format(request_dict))
|
|
@@ -52,73 +56,72 @@ 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)
|
|
|
- # 往来检测 1:来,2:离开
|
|
|
- dealings_type = request_dict.get('dealingsType', 0)
|
|
|
- # 检测类型 0:普通,1:算法
|
|
|
+ dealings_type = int(request_dict.get('dealingsType', 0))
|
|
|
detection = int(request_dict.get('detection', 0))
|
|
|
|
|
|
+ # 参数校验
|
|
|
if not all([channel, n_time]):
|
|
|
- return JsonResponse(status=200, data={
|
|
|
- 'code': 444,
|
|
|
- 'msg': 'param is wrong'})
|
|
|
+ return JsonResponse(status=200, data={'code': 444, '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'})
|
|
|
+
|
|
|
+ is_st = int(is_st)
|
|
|
+ region = int(region)
|
|
|
+ event_type = int(event_type)
|
|
|
+
|
|
|
try:
|
|
|
- is_st = int(is_st)
|
|
|
- region = int(region)
|
|
|
- event_type = int(event_type)
|
|
|
- if not uid:
|
|
|
- uid = DevicePushService.decode_uid(etk, uidToken) # 解密uid
|
|
|
+ uid = DevicePushService.decode_uid(etk, uidToken)
|
|
|
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)) # 判断事件类型是否是系统消息
|
|
|
+
|
|
|
+ # 判断是否为系统消息
|
|
|
+ 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)
|
|
|
+ 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))
|
|
|
+
|
|
|
+ redis_obj = RedisObject()
|
|
|
+ req_limiting = '{uid}_{channel}_{event_type}_ptl'.format(uid=uid, channel=channel, event_type=event_type)
|
|
|
+ cache_req_limiting = redis_obj.get_data(key=req_limiting) # 获取请求限流缓存数据
|
|
|
+ cache_app_push = redis_obj.get_data(key=push_interval) # 获取APP推送消息时间间隔缓存数据
|
|
|
+ logger.info('V2推送 - 限流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, event_type) # 查询uid_set与push数据列表
|
|
|
+ redis_obj.set_data(key=req_limiting, val=1, expire=60) # 当缓存不存在限流数据 重新设置一分钟请求一次
|
|
|
+
|
|
|
+ # 查询uid_push和uid_set数据
|
|
|
+ uid_push_qs = DevicePushService.query_uid_push(uid, event_type)
|
|
|
if not uid_push_qs.exists():
|
|
|
logger.info('消息推送-{}uid_push数据不存在'.format(uid))
|
|
|
return JsonResponse(status=200, data={'code': 176, 'msg': 'no uid_push data'})
|
|
|
+
|
|
|
ai_type = uid_push_qs.first()['uid_set__ai_type']
|
|
|
device_type = uid_push_qs.first()['uid_set__device_type']
|
|
|
- logger.info('ai_type: {}, device_type: {}'.format(ai_type, device_type))
|
|
|
- # 将uid_set以及uid_push 转数组列表
|
|
|
- uid_set_push_list = DevicePushService.cache_uid_push(uid_push_qs)
|
|
|
+
|
|
|
+ # uid_push_qs转存列表
|
|
|
+ uid_set_push_list = DevicePushService.qs_to_list(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,
|
|
|
+ DevicePushService.cache_push_detect_interval(redis_obj, push_interval, detect_interval,
|
|
|
uid_set_push_list[0]['uid_set__new_detect_interval'])
|
|
|
else:
|
|
|
cache_app_push = ''
|
|
|
+
|
|
|
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,
|
|
@@ -129,13 +132,15 @@ class NotificationV2View(View):
|
|
|
'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, 'ai_type': ai_type, 'device_type': device_type,
|
|
|
- 'dealings_type': int(dealings_type), 'detection': detection}
|
|
|
+ 'dealings_type': dealings_type, 'detection': detection}
|
|
|
logger.info('推送数据参数:{}'.format(params))
|
|
|
+
|
|
|
# 推送消息,生成推送数据列表
|
|
|
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
|