|
@@ -323,50 +323,46 @@ class NotificationView(View):
|
|
'userID_id', 'userID__NickName',
|
|
'userID_id', 'userID__NickName',
|
|
'interval')
|
|
'interval')
|
|
if uid_set_qs.exists():
|
|
if uid_set_qs.exists():
|
|
- pass
|
|
|
|
|
|
+ redisObj = RedisObject(db=6)
|
|
|
|
+ pkey = '{uid}_{channel}_ptl'.format(uid=uid, channel=channel)
|
|
|
|
+ if redisObj.get_data(key=pkey):
|
|
|
|
+ res_data = {'code': 0, 'msg': 'success,!'}
|
|
|
|
+ return JsonResponse(status=200, data=res_data)
|
|
|
|
+ else:
|
|
|
|
+ detect_interval = UidSetModel[0].detect_interval
|
|
|
|
+ if detect_interval:
|
|
|
|
+ redisObj.set_data(key=pkey, val=1, expire=detect_interval)
|
|
|
|
+
|
|
|
|
+ auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
|
|
|
|
+ bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
|
|
|
|
+ for up in uid_push_qs:
|
|
|
|
+ push_type = up['push_type']
|
|
|
|
+ # ios apns
|
|
|
|
+ if push_type == 0:
|
|
|
|
+ self.do_apns(request_dict, up, response)
|
|
|
|
+ # android gcm
|
|
|
|
+ elif push_type == 1:
|
|
|
|
+ self.do_gmc(request_dict, up, response)
|
|
|
|
+ # android jpush
|
|
|
|
+ elif push_type == 2:
|
|
|
|
+ self.do_jpush(request_dict, up, response)
|
|
|
|
+ # self.do_save_equipment_info(ua, n_time, channel, event_type, is_st)
|
|
|
|
+ # 需求不一样,所以这么做的
|
|
|
|
+ self.do_bulk_create_info(uid_push_qs, n_time, channel, event_type, is_st)
|
|
|
|
+ if is_st == '0' or is_st == '2':
|
|
|
|
+ return JsonResponse(status=200, data={'code': 0, 'msg': 'success'})
|
|
|
|
+ else:
|
|
|
|
+ # 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)
|
|
else:
|
|
else:
|
|
return JsonResponse(status=200, data={'code': 404, 'msg': 'data is not exist'})
|
|
return JsonResponse(status=200, data={'code': 404, 'msg': 'data is not exist'})
|
|
else:
|
|
else:
|
|
return JsonResponse(status=200, data={'code': 404, 'msg': 'data is not exist'})
|
|
return JsonResponse(status=200, data={'code': 404, 'msg': 'data is not exist'})
|
|
|
|
|
|
- # if uaqs.exists():
|
|
|
|
- # redisObj = RedisObject(db=6)
|
|
|
|
- #
|
|
|
|
- # auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
|
|
|
|
- # bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
|
|
|
|
- #
|
|
|
|
- # for ua in uaqs:
|
|
|
|
- # push_type = ua['push_type']
|
|
|
|
- # pkey = '{uid}_{channel}_ptl'.format(uid=uid, channel=channel)
|
|
|
|
- # if redisObj.get_data(key=pkey):
|
|
|
|
- # res_data = {'code': 0, 'msg': 'success,!'}
|
|
|
|
- # return JsonResponse(status=200, data=res_data)
|
|
|
|
- # else:
|
|
|
|
- # if ua['interval']:
|
|
|
|
- # redisObj.set_data(key=pkey, val=1, expire=ua['interval'])
|
|
|
|
- # # ios apns
|
|
|
|
- # if push_type == 0:
|
|
|
|
- # self.do_apns(request_dict, ua, response)
|
|
|
|
- # # android gcm
|
|
|
|
- # elif push_type == 1:
|
|
|
|
- # self.do_gmc(request_dict, ua, response)
|
|
|
|
- # # android jpush
|
|
|
|
- # elif push_type == 2:
|
|
|
|
- # self.do_jpush(request_dict, ua, response)
|
|
|
|
- #
|
|
|
|
- # # self.do_save_equipment_info(ua, n_time, channel, event_type, is_st)
|
|
|
|
- # # 需求不一样,所以这么做的
|
|
|
|
- # self.do_bulk_create_info(uaqs, n_time, channel, event_type, is_st)
|
|
|
|
- # if is_st == '0' or is_st == '2':
|
|
|
|
- # return JsonResponse(status=200, data={'code': 0, 'msg': 'success'})
|
|
|
|
- # else:
|
|
|
|
- # # 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)
|
|
|
|
-
|
|
|
|
def do_jpush(self, request_dict, uaql, response):
|
|
def do_jpush(self, request_dict, uaql, response):
|
|
event_type = request_dict.get('event_type', None)
|
|
event_type = request_dict.get('event_type', None)
|
|
jpush_config = {
|
|
jpush_config = {
|
|
@@ -494,18 +490,6 @@ class NotificationView(View):
|
|
except Exception as e:
|
|
except Exception as e:
|
|
return response.json(10, repr(e))
|
|
return response.json(10, repr(e))
|
|
|
|
|
|
- def do_save_equipment_info(self, uaql, n_time, channel, event_type, is_st):
|
|
|
|
- Equipment_Info.objects.create(
|
|
|
|
- userID_id=uaql['userID_id'],
|
|
|
|
- eventTime=n_time,
|
|
|
|
- eventType=event_type,
|
|
|
|
- devUid=uaql['uid'],
|
|
|
|
- devNickName=uaql['userID__NickName'],
|
|
|
|
- Channel=channel,
|
|
|
|
- alarm='0',
|
|
|
|
- is_st=int(is_st),
|
|
|
|
- receiveTime=n_time)
|
|
|
|
-
|
|
|
|
def do_bulk_create_info(self, uaqs, n_time, channel, event_type, is_st):
|
|
def do_bulk_create_info(self, uaqs, n_time, channel, event_type, is_st):
|
|
#
|
|
#
|
|
qs_list = []
|
|
qs_list = []
|
|
@@ -516,7 +500,7 @@ class NotificationView(View):
|
|
'eventTime': n_time,
|
|
'eventTime': n_time,
|
|
'eventType': event_type,
|
|
'eventType': event_type,
|
|
'devUid': dv['uid'],
|
|
'devUid': dv['uid'],
|
|
- 'devNickName': dv['userID__NickName'],
|
|
|
|
|
|
+ 'devNickName': '',
|
|
'Channel': channel,
|
|
'Channel': channel,
|
|
'alarm': 'Motion \tChannel:{channel}'.format(channel=channel),
|
|
'alarm': 'Motion \tChannel:{channel}'.format(channel=channel),
|
|
'is_st': int(is_st),
|
|
'is_st': int(is_st),
|