|
@@ -78,6 +78,7 @@ class NotificationView(View):
|
|
|
if redisObj.get_data(key=pkey):
|
|
|
res_data = {'code': 0, 'msg': 'success!'}
|
|
|
return JsonResponse(status=200, data=res_data)
|
|
|
+
|
|
|
# 第一次,没有,没有dkey,也没有ykey
|
|
|
if not redisObj.get_data(key=dkey) and not redisObj.get_data(key=ykey):
|
|
|
print("第一次进来,设置dkey和pkey为interval秒")
|
|
@@ -89,12 +90,12 @@ class NotificationView(View):
|
|
|
values('token_val', 'app_type', 'appBundleId',
|
|
|
'push_type', 'userID_id', 'lang',
|
|
|
'tz', 'uid_set__nickname', 'uid_set__detect_interval', 'uid_set__detect_group')
|
|
|
- print(uid_push_qs)
|
|
|
- first_redis_list = []
|
|
|
+ # 用来判断是否推送
|
|
|
+ first_redis_list = 1
|
|
|
+ redis_list = []
|
|
|
# 把数据库数据追加进redis_list
|
|
|
for qs in uid_push_qs:
|
|
|
- first_redis_list.append(qs)
|
|
|
- redis_list = first_redis_list
|
|
|
+ redis_list.append(qs)
|
|
|
detect_interval = redis_list[0]['uid_set__detect_interval']
|
|
|
detect_group = redis_list[0]['uid_set__detect_group']
|
|
|
if detect_group:
|
|
@@ -201,11 +202,12 @@ class NotificationView(View):
|
|
|
img_url_list.append(url)
|
|
|
res_data = {'code': 0, 'img_url_list': img_url_list, 'msg': 'success'}
|
|
|
return JsonResponse(status=200, data=res_data)
|
|
|
+
|
|
|
# 第三次,有dkey,也有ykey(一分钟外,10分钟内)
|
|
|
- if redisObj.get_data(key=dkey) and redisObj.get_data(key=ykey):
|
|
|
+ if redisObj.get_data(key=dkey) and redisObj.get_data(key=ykey):
|
|
|
redis_data = redisObj.get_data(key=ykey)
|
|
|
if redis_data:
|
|
|
- first_redis_list = ''
|
|
|
+ first_redis_list = 0
|
|
|
redis_list = eval(redis_data)
|
|
|
if redis_list:
|
|
|
nickname = redis_list[0]['uid_set__nickname']
|
|
@@ -305,12 +307,130 @@ class NotificationView(View):
|
|
|
img_url_list.append(url)
|
|
|
res_data = {'code': 0, 'img_url_list': img_url_list, 'msg': 'success'}
|
|
|
return JsonResponse(status=200, data=res_data)
|
|
|
+
|
|
|
#第四次,没有dkey,有ykey(1分钟外,10分钟内 )
|
|
|
if not redisObj.get_data(key=dkey) and redisObj.get_data(key=ykey):
|
|
|
redis_data = redisObj.get_data(key=ykey)
|
|
|
if redis_data:
|
|
|
- first_redis_list = ''
|
|
|
+ first_redis_list = 1
|
|
|
redis_list = eval(redis_data)
|
|
|
+ # 再次设置推送时间为60秒一次
|
|
|
+ redisObj.set_data(key=pkey, val=1, expire=60)
|
|
|
+ detect_interval = redis_list[0]['uid_set__detect_interval']
|
|
|
+ detect_group = redis_list[0]['uid_set__detect_group']
|
|
|
+ if detect_group:
|
|
|
+ detect_group_list = detect_group.split(',')
|
|
|
+ if event_type in detect_group_list:
|
|
|
+ redisObj.set_data(key=dkey, val=1, expire=detect_interval)
|
|
|
+ if redis_list:
|
|
|
+ nickname = redis_list[0]['uid_set__nickname']
|
|
|
+ now_time = int(time.time())
|
|
|
+ if not nickname:
|
|
|
+ nickname = uid
|
|
|
+ # 判断是否为系统类通知
|
|
|
+ is_sys_msg = self.is_sys_msg(int(event_type))
|
|
|
+ auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
|
|
|
+ bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
|
|
|
+ kwag_args = {
|
|
|
+ 'uid': uid,
|
|
|
+ 'channel': channel,
|
|
|
+ 'event_type': event_type,
|
|
|
+ 'n_time': n_time,
|
|
|
+ # 'appBundleId': appBundleId,
|
|
|
+ # 'token_val': token_val,
|
|
|
+ # 'msg_title': msg_title,
|
|
|
+ # 'msg_text': msg_text
|
|
|
+ }
|
|
|
+ eq_list = []
|
|
|
+ sys_msg_list = []
|
|
|
+ userID_ids = []
|
|
|
+ for up in redis_list:
|
|
|
+ push_type = up['push_type']
|
|
|
+ appBundleId = up['appBundleId']
|
|
|
+ token_val = up['token_val']
|
|
|
+ lang = up['lang']
|
|
|
+ tz = up['tz']
|
|
|
+ # 发送标题
|
|
|
+ msg_title = self.get_msg_title(appBundleId=appBundleId, nickname=nickname)
|
|
|
+ # 发送内容
|
|
|
+ msg_text = self.get_msg_text(channel=channel, n_time=n_time, lang=lang, tz=tz,
|
|
|
+ event_type=event_type)
|
|
|
+ kwag_args['appBundleId'] = appBundleId
|
|
|
+ kwag_args['token_val'] = token_val
|
|
|
+ kwag_args['msg_title'] = msg_title
|
|
|
+ kwag_args['msg_text'] = msg_text
|
|
|
+ if first_redis_list:
|
|
|
+ if push_type == 0: # ios apns
|
|
|
+ self.do_apns(**kwag_args)
|
|
|
+ elif push_type == 1: # android gcm
|
|
|
+ self.do_fcm(**kwag_args)
|
|
|
+ elif push_type == 2: # android jpush
|
|
|
+ self.do_jpush(**kwag_args)
|
|
|
+ userID_id = up["userID_id"]
|
|
|
+ int_is_st = int(is_st)
|
|
|
+ if userID_id not in userID_ids:
|
|
|
+ eq_list.append(Equipment_Info(
|
|
|
+ userID_id=userID_id,
|
|
|
+ eventTime=n_time,
|
|
|
+ eventType=event_type,
|
|
|
+ devUid=uid,
|
|
|
+ devNickName=nickname,
|
|
|
+ Channel=channel,
|
|
|
+ alarm='Motion \tChannel:{channel}'.format(channel=channel),
|
|
|
+ is_st=int_is_st,
|
|
|
+ receiveTime=n_time,
|
|
|
+ addTime=now_time
|
|
|
+ ))
|
|
|
+ if is_sys_msg:
|
|
|
+ sys_msg_text = self.get_msg_text(channel=channel, n_time=n_time, lang=lang, tz=tz,
|
|
|
+ event_type=event_type, is_sys=1)
|
|
|
+ sys_msg_list.append(SysMsgModel(
|
|
|
+ userID_id=userID_id,
|
|
|
+ msg=sys_msg_text,
|
|
|
+ addTime=now_time,
|
|
|
+ updTime=now_time,
|
|
|
+ uid=uid,
|
|
|
+ eventType=event_type))
|
|
|
+ userID_ids.append(userID_id)
|
|
|
+
|
|
|
+ if is_sys_msg:
|
|
|
+ SysMsgModel.objects.bulk_create(sys_msg_list)
|
|
|
+ Equipment_Info.objects.bulk_create(eq_list)
|
|
|
+ # 以下是存库
|
|
|
+ if is_st == '0' or is_st == '2':
|
|
|
+ return JsonResponse(status=200, data={'code': 0, 'msg': 'success'})
|
|
|
+ elif is_st == '1':
|
|
|
+ # Endpoint以杭州为例,其它Region请按实际情况填写。
|
|
|
+ obj = '{uid}/{channel}/{filename}.jpeg'.format(uid=uid, channel=channel, filename=n_time)
|
|
|
+ # 设置此签名URL在60秒内有效。
|
|
|
+ url = bucket.sign_url('PUT', obj, 7200)
|
|
|
+ res_data = {'code': 0, 'img_push': url, 'msg': 'success'}
|
|
|
+ return JsonResponse(status=200, data=res_data)
|
|
|
+ elif is_st == '3':
|
|
|
+ # 人形检测带动图
|
|
|
+ # Endpoint以杭州为例,其它Region请按实际情况填写。
|
|
|
+ img_url_list = []
|
|
|
+ for i in range(int(is_st)):
|
|
|
+ obj = '{uid}/{channel}/{filename}_{st}.jpeg'. \
|
|
|
+ format(uid=uid, channel=channel, filename=n_time, st=i)
|
|
|
+ # 设置此签名URL在60秒内有效。
|
|
|
+ url = bucket.sign_url('PUT', obj, 7200)
|
|
|
+ img_url_list.append(url)
|
|
|
+ res_data = {'code': 0, 'img_url_list': img_url_list, 'msg': 'success'}
|
|
|
+ return JsonResponse(status=200, data=res_data)
|
|
|
+
|
|
|
+ # 第五次,有dkey,没有ykey
|
|
|
+ if redisObj.get_data(key=dkey) and not redisObj.get_data(key=ykey):
|
|
|
+ uid_push_qs = UidPushModel.objects.filter(uid_set__uid='HLK7EJ2VYLNHHUMG111A'). \
|
|
|
+ values('token_val', 'app_type', 'appBundleId',
|
|
|
+ 'push_type', 'userID_id', 'lang',
|
|
|
+ 'tz', 'uid_set__nickname', 'uid_set__detect_interval', 'uid_set__detect_group')
|
|
|
+ redis_list = []
|
|
|
+ # 把数据库数据追加进redis_list
|
|
|
+ for qs in uid_push_qs:
|
|
|
+ redis_list.append(qs)
|
|
|
+ redisObj.set_data(key=ykey, val=str(redis_list), expire=600)
|
|
|
+ first_redis_list = 0
|
|
|
if redis_list:
|
|
|
nickname = redis_list[0]['uid_set__nickname']
|
|
|
now_time = int(time.time())
|
|
@@ -348,6 +468,7 @@ class NotificationView(View):
|
|
|
kwag_args['token_val'] = token_val
|
|
|
kwag_args['msg_title'] = msg_title
|
|
|
kwag_args['msg_text'] = msg_text
|
|
|
+ # 第一次进来,才推送
|
|
|
if first_redis_list:
|
|
|
if push_type == 0: # ios apns
|
|
|
self.do_apns(**kwag_args)
|