|
@@ -43,14 +43,15 @@ class NotificationView(View):
|
|
|
# operation = kwargs.get('operation')
|
|
|
return self.validation(request.GET)
|
|
|
|
|
|
- # def post(self, request, *args, **kwargs):
|
|
|
- # request.encoding = 'utf-8'
|
|
|
- # # operation = kwargs.get('operation')
|
|
|
- # return self.validation(request.POST)
|
|
|
+ def post(self, request, *args, **kwargs):
|
|
|
+ request.encoding = 'utf-8'
|
|
|
+ # operation = kwargs.get('operation')
|
|
|
+ return self.validation(request.POST)
|
|
|
|
|
|
def validation(self, request_dict):
|
|
|
response = ResponseObject()
|
|
|
uidToken = request_dict.get('uidToken', None)
|
|
|
+ etk = request_dict.get('etk', None)
|
|
|
channel = request_dict.get('channel', '1')
|
|
|
n_time = request_dict.get('n_time', None)
|
|
|
event_type = request_dict.get('event_type', None)
|
|
@@ -60,8 +61,14 @@ class NotificationView(View):
|
|
|
'code': 444,
|
|
|
'msg': 'param is wrong'})
|
|
|
# return response.json(444) # 执行下面utko窗口会输出{'uid',""}
|
|
|
- utko = UidTokenObject(uidToken)
|
|
|
- uid = utko.UID
|
|
|
+ if etk:
|
|
|
+ eto = ETkObject(etk)
|
|
|
+ uid = eto.uid
|
|
|
+ if len(uid) != 20:
|
|
|
+ return JsonResponse(status=200, data={'code': 404, 'msg': 'data is not exist'})
|
|
|
+ else:
|
|
|
+ utko = UidTokenObject(uidToken)
|
|
|
+ uid = utko.UID
|
|
|
redisObj = RedisObject(db=6)
|
|
|
# pkey = '{uid}_{channel}_ptl'.format(uid=uid, channel=channel)
|
|
|
pkey = '{uid}_ptl'.format(uid=uid)
|
|
@@ -72,8 +79,8 @@ class NotificationView(View):
|
|
|
return JsonResponse(status=200, data=res_data)
|
|
|
else:
|
|
|
# 设置推送时间为60秒一次
|
|
|
- redisObj.set_data(key=pkey,val=1,expire=60)
|
|
|
- print("从数据库查到数据")
|
|
|
+ redisObj.set_data(key=pkey, val=1, expire=60)
|
|
|
+ # print("从数据库查到数据")
|
|
|
# 从数据库查询出来
|
|
|
uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid). \
|
|
|
values('token_val', 'app_type', 'appBundleId',
|
|
@@ -106,7 +113,7 @@ class NotificationView(View):
|
|
|
self.do_jpush(request_dict, up, response, uid, channel, nickname)
|
|
|
# self.do_save_equipment_info(ua, n_time, channel, event_type, is_st)
|
|
|
# 需求不一样,所以这么做的
|
|
|
- self.do_bulk_create_info(redis_list, n_time, channel, event_type, is_st, uid)
|
|
|
+ self.do_bulk_create_info(redis_list, n_time, channel, event_type, is_st, uid,nickname)
|
|
|
if is_st == '0' or is_st == '2':
|
|
|
return JsonResponse(status=200, data={'code': 0, 'msg': 'success'})
|
|
|
elif is_st == '1':
|
|
@@ -131,7 +138,6 @@ class NotificationView(View):
|
|
|
else:
|
|
|
return JsonResponse(status=200, data={'code': 404, 'msg': 'data is not exist'})
|
|
|
|
|
|
-
|
|
|
def do_jpush(self, request_dict, uaql, response, uid, channel, nickname):
|
|
|
event_type = request_dict.get('event_type', None)
|
|
|
n_time = request_dict.get('n_time', None)
|
|
@@ -261,7 +267,7 @@ class NotificationView(View):
|
|
|
print(repr(e))
|
|
|
return response.json(10, repr(e))
|
|
|
|
|
|
- def do_bulk_create_info(self, uaqs, n_time, channel, event_type, is_st, uid):
|
|
|
+ def do_bulk_create_info(self, uaqs, n_time, channel, event_type, is_st, uid,nickname):
|
|
|
#
|
|
|
qs_list = []
|
|
|
nowTime = int(time.time())
|
|
@@ -275,7 +281,7 @@ class NotificationView(View):
|
|
|
'eventTime': n_time,
|
|
|
'eventType': event_type,
|
|
|
'devUid': uid,
|
|
|
- 'devNickName': uid,
|
|
|
+ 'devNickName': nickname,
|
|
|
'Channel': channel,
|
|
|
'alarm': 'Motion \tChannel:{channel}'.format(channel=channel),
|
|
|
'is_st': int(is_st),
|
|
@@ -285,7 +291,6 @@ class NotificationView(View):
|
|
|
qs_list.append(Equipment_Info(**add_data))
|
|
|
userID_ids.append(userID_id)
|
|
|
if qs_list:
|
|
|
- print(1)
|
|
|
Equipment_Info.objects.bulk_create(qs_list)
|
|
|
return True
|
|
|
else:
|
|
@@ -323,9 +328,9 @@ class PushNotificationView(View):
|
|
|
return JsonResponse(status=200, data=res_data)
|
|
|
else:
|
|
|
redisObj.set_data(key=pkey, val=1, expire=60)
|
|
|
- uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid,uid_set__detect_status=1). \
|
|
|
+ uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid, uid_set__detect_status=1). \
|
|
|
values('token_val', 'app_type', 'appBundleId', 'push_type',
|
|
|
- 'userID_id', 'userID__NickName', 'lang', 'tz','uid_set__nickname')
|
|
|
+ 'userID_id', 'userID__NickName', 'lang', 'tz', 'uid_set__nickname')
|
|
|
if uid_push_qs.exists():
|
|
|
auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
|
|
|
bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
|