|
@@ -154,117 +154,6 @@ class DetectControllerView(View):
|
|
res.append(p)
|
|
res.append(p)
|
|
return response.json(0, {'datas': res, 'count': count})
|
|
return response.json(0, {'datas': res, 'count': count})
|
|
|
|
|
|
- def do_change_status1(self, userID, request_dict, response):
|
|
|
|
- uid = request_dict.get('uid', None)
|
|
|
|
- token_val = request_dict.get('token_val', None)
|
|
|
|
- appBundleId = request_dict.get('appBundleId', None)
|
|
|
|
- app_type = request_dict.get('app_type', None)
|
|
|
|
- push_type = request_dict.get('push_type', None)
|
|
|
|
- status = request_dict.get('status', None)
|
|
|
|
- m_code = request_dict.get('m_code', None)
|
|
|
|
- # 设备语言
|
|
|
|
- lang = request_dict.get('lang', 'en')
|
|
|
|
- tz = request_dict.get('tz', '0')
|
|
|
|
- # interval = request_dict.get('interval', None)
|
|
|
|
- if not status:
|
|
|
|
- return response.json(444, 'status')
|
|
|
|
- # 关闭推送
|
|
|
|
- if not all([appBundleId, app_type, token_val, uid, m_code]):
|
|
|
|
- return response.json(444, 'appBundleId,app_type,token_val,uid,m_code')
|
|
|
|
- # 判断推送类型对应key是否存在
|
|
|
|
- if push_type == '0':
|
|
|
|
- if appBundleId not in APNS_CONFIG.keys():
|
|
|
|
- return response.json(904)
|
|
|
|
- elif push_type == '1':
|
|
|
|
- if appBundleId not in FCM_CONFIG.keys():
|
|
|
|
- return response.json(904)
|
|
|
|
- elif push_type == '2':
|
|
|
|
- if appBundleId not in JPUSH_CONFIG.keys():
|
|
|
|
- return response.json(904)
|
|
|
|
- else:
|
|
|
|
- return response.json(173)
|
|
|
|
- dvqs = Device_Info.objects.filter(userID_id=userID, UID=uid)
|
|
|
|
- status = int(status)
|
|
|
|
- if dvqs.exists():
|
|
|
|
- # 获取用户区域
|
|
|
|
- # ip = self.ip
|
|
|
|
- # ipInfo = CommonService.getIpIpInfo(ip=ip, lang='EN')
|
|
|
|
- # area = ipInfo['country_name']
|
|
|
|
- # if area == 'China':
|
|
|
|
- # DETECT_PUSH_DOMAIN = 'cn.push.dvema.com'
|
|
|
|
- # else:
|
|
|
|
- # DETECT_PUSH_DOMAIN = 'en.push.dvema.com'
|
|
|
|
- nowTime = int(time.time())
|
|
|
|
- uid_set_qs = UidSetModel.objects. \
|
|
|
|
- filter(uid=uid, uidpushmodel__userID_id=userID, uidpushmodel__m_code=m_code)
|
|
|
|
- # 判断是否有曾经开启过
|
|
|
|
- if uid_set_qs.exists():
|
|
|
|
- uid_push_update_dict = {
|
|
|
|
- 'appBundleId': appBundleId,
|
|
|
|
- 'app_type': app_type,
|
|
|
|
- 'push_type': push_type,
|
|
|
|
- 'token_val': token_val,
|
|
|
|
- 'updTime': nowTime,
|
|
|
|
- 'lang': lang,
|
|
|
|
- 'tz': tz
|
|
|
|
- }
|
|
|
|
- uid_set_qs.update(detect_status=status, updTime=nowTime)
|
|
|
|
- UidPushModel.objects.filter(userID_id=userID, m_code=m_code, uid_set__uid=uid). \
|
|
|
|
- update(**uid_push_update_dict)
|
|
|
|
- if status == 0:
|
|
|
|
- # 关闭成功
|
|
|
|
- return response.json(0)
|
|
|
|
- utko = UidTokenObject()
|
|
|
|
- # right
|
|
|
|
- utko.generate(data={'uid': uid})
|
|
|
|
- detectUrl = "{DETECT_PUSH_DOMAIN}notify/push?uidToken={uidToken}". \
|
|
|
|
- format(uidToken=utko.token, DETECT_PUSH_DOMAIN=DETECT_PUSH_DOMAIN)
|
|
|
|
- return response.json(0, {'detectUrl': detectUrl})
|
|
|
|
- else:
|
|
|
|
- uid_set_qs = UidSetModel.objects.filter(uid=uid)
|
|
|
|
- # 判断uid push是否绑定
|
|
|
|
- if not uid_set_qs.exists():
|
|
|
|
- uid_set_create_dict = {
|
|
|
|
- 'uid': uid,
|
|
|
|
- 'addTime': nowTime,
|
|
|
|
- 'updTime': nowTime,
|
|
|
|
- 'detect_status': status,
|
|
|
|
- }
|
|
|
|
- # 添加设备配置
|
|
|
|
- uid_set_qs = UidSetModel.objects.create(**uid_set_create_dict)
|
|
|
|
- uid_set_id = uid_set_qs.id
|
|
|
|
- else:
|
|
|
|
- update_dict = {
|
|
|
|
- 'updTime': nowTime,
|
|
|
|
- 'detect_status': status,
|
|
|
|
- }
|
|
|
|
- uid_set_qs.update(**update_dict)
|
|
|
|
- uid_set_id = uid_set_qs[0].id
|
|
|
|
- uid_push_create_dict = {
|
|
|
|
- 'uid_set_id': uid_set_id,
|
|
|
|
- 'userID_id': userID,
|
|
|
|
- 'appBundleId': appBundleId,
|
|
|
|
- 'app_type': app_type,
|
|
|
|
- 'push_type': push_type,
|
|
|
|
- 'token_val': token_val,
|
|
|
|
- 'm_code': m_code,
|
|
|
|
- 'addTime': nowTime,
|
|
|
|
- 'updTime': nowTime,
|
|
|
|
- 'lang': lang,
|
|
|
|
- 'tz': tz
|
|
|
|
- }
|
|
|
|
- # 绑定设备推送
|
|
|
|
- UidPushModel.objects.create(**uid_push_create_dict)
|
|
|
|
- if status == 0:
|
|
|
|
- return response.json(0)
|
|
|
|
- utko = UidTokenObject()
|
|
|
|
- utko.generate(data={'uid': uid})
|
|
|
|
- detectUrl = "{DETECT_PUSH_DOMAIN}notify/push?uidToken={uidToken}". \
|
|
|
|
- format(uidToken=utko.token, DETECT_PUSH_DOMAIN=DETECT_PUSH_DOMAIN)
|
|
|
|
- return response.json(0, {'detectUrl': detectUrl})
|
|
|
|
- else:
|
|
|
|
- return response.json(14)
|
|
|
|
-
|
|
|
|
def do_change_status(self, userID, request_dict, response):
|
|
def do_change_status(self, userID, request_dict, response):
|
|
uid = request_dict.get('uid', None)
|
|
uid = request_dict.get('uid', None)
|
|
token_val = request_dict.get('token_val', None)
|
|
token_val = request_dict.get('token_val', None)
|
|
@@ -354,11 +243,13 @@ class DetectControllerView(View):
|
|
}
|
|
}
|
|
# 绑定设备推送
|
|
# 绑定设备推送
|
|
UidPushModel.objects.create(**uid_push_create_dict)
|
|
UidPushModel.objects.create(**uid_push_create_dict)
|
|
- utko = UidTokenObject()
|
|
|
|
- # right
|
|
|
|
- utko.generate(data={'uid': uid})
|
|
|
|
- detectUrl = "{DETECT_PUSH_DOMAIN}notify/push?uidToken={uidToken}". \
|
|
|
|
- format(uidToken=utko.token, DETECT_PUSH_DOMAIN=DETECT_PUSH_DOMAIN)
|
|
|
|
|
|
+ # utko = UidTokenObject()
|
|
|
|
+ # # right
|
|
|
|
+ # utko.generate(data={'uid': uid})
|
|
|
|
+ etkObj = ETkObject(etk='')
|
|
|
|
+ etk = etkObj.encrypt(uid)
|
|
|
|
+ detectUrl = "{DETECT_PUSH_DOMAIN}notify/push?etk={etk}". \
|
|
|
|
+ format(etk=etk, DETECT_PUSH_DOMAIN=DETECT_PUSH_DOMAIN)
|
|
return response.json(0, {'detectUrl': detectUrl})
|
|
return response.json(0, {'detectUrl': detectUrl})
|
|
else:
|
|
else:
|
|
return response.json(14)
|
|
return response.json(14)
|
|
@@ -396,6 +287,7 @@ class NotificationView(View):
|
|
def validation(self, request_dict):
|
|
def validation(self, request_dict):
|
|
response = ResponseObject()
|
|
response = ResponseObject()
|
|
uidToken = request_dict.get('uidToken', None)
|
|
uidToken = request_dict.get('uidToken', None)
|
|
|
|
+ etk = request_dict.get('etk', None)
|
|
channel = request_dict.get('channel', '1')
|
|
channel = request_dict.get('channel', '1')
|
|
n_time = request_dict.get('n_time', None)
|
|
n_time = request_dict.get('n_time', None)
|
|
event_type = request_dict.get('event_type', None)
|
|
event_type = request_dict.get('event_type', None)
|
|
@@ -405,8 +297,16 @@ class NotificationView(View):
|
|
'code': 444,
|
|
'code': 444,
|
|
'msg': 'param is wrong'})
|
|
'msg': 'param is wrong'})
|
|
# return response.json(444)
|
|
# return response.json(444)
|
|
- 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
|
|
|
|
+ # utko = UidTokenObject(uidToken)
|
|
|
|
+ # uid = utko.UID
|
|
redisObj = RedisObject(db=6)
|
|
redisObj = RedisObject(db=6)
|
|
# pkey = '{uid}_{channel}_ptl'.format(uid=uid, channel=channel)
|
|
# pkey = '{uid}_{channel}_ptl'.format(uid=uid, channel=channel)
|
|
pkey = '{uid}_ptl'.format(uid=uid)
|
|
pkey = '{uid}_ptl'.format(uid=uid)
|
|
@@ -605,12 +505,16 @@ class NotificationView(View):
|
|
for dv in uaqs:
|
|
for dv in uaqs:
|
|
userID_id = dv["userID_id"]
|
|
userID_id = dv["userID_id"]
|
|
if userID_id not in userID_ids:
|
|
if userID_id not in userID_ids:
|
|
|
|
+ if dv['uid_set__nickname']:
|
|
|
|
+ uid_nickname = dv['uid_set__nickname']
|
|
|
|
+ else:
|
|
|
|
+ uid_nickname = uid
|
|
add_data = {
|
|
add_data = {
|
|
'userID_id': dv["userID_id"],
|
|
'userID_id': dv["userID_id"],
|
|
'eventTime': n_time,
|
|
'eventTime': n_time,
|
|
'eventType': event_type,
|
|
'eventType': event_type,
|
|
'devUid': uid,
|
|
'devUid': uid,
|
|
- 'devNickName': uid,
|
|
|
|
|
|
+ 'devNickName': uid_nickname,
|
|
'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),
|