|
@@ -90,7 +90,7 @@ class DetectControllerView(View):
|
|
|
if uids:
|
|
|
uid_list = uids.split(',')
|
|
|
qs = qs.filter(devUid__in=uid_list)
|
|
|
- dvqs = Device_Info.objects.filter(UID__in=uid_list).values('UID','Type', 'NickName')
|
|
|
+ dvqs = Device_Info.objects.filter(UID__in=uid_list).values('UID', 'Type', 'NickName')
|
|
|
uid_type_dict = {}
|
|
|
for dv in dvqs:
|
|
|
uid_type_dict[dv['UID']] = {'type': dv['Type'], 'NickName': dv['NickName']}
|
|
@@ -142,7 +142,7 @@ class DetectControllerView(View):
|
|
|
res.append(p)
|
|
|
return response.json(0, {'datas': res, 'count': count})
|
|
|
|
|
|
- def do_change_status(self, userID, request_dict, response):
|
|
|
+ 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)
|
|
@@ -253,6 +253,104 @@ class DetectControllerView(View):
|
|
|
else:
|
|
|
return response.json(14)
|
|
|
|
|
|
+ def do_change_status(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)
|
|
|
+ # 获取用户区域
|
|
|
+ # 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())
|
|
|
+ if dvqs.exists():
|
|
|
+ uid_set_qs = UidSetModel.objects.filter(uid=uid)
|
|
|
+ # uid配置信息是否存在
|
|
|
+ if uid_set_qs.exists():
|
|
|
+ uid_set_id = uid_set_qs[0].id
|
|
|
+ else:
|
|
|
+ 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
|
|
|
+ uid_set_qs.update(detect_status=status, updTime=nowTime)
|
|
|
+ if status == 0:
|
|
|
+ UidPushModel.objects.filter(uid_set__uid=uid).delete()
|
|
|
+ return response.json(0)
|
|
|
+ elif status == 1:
|
|
|
+ uid_push_qs = UidPushModel.objects.filter(userID_id=userID, m_code=m_code, uid_set__uid=uid)
|
|
|
+ if uid_push_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_push_qs.update(**uid_push_update_dict)
|
|
|
+ else:
|
|
|
+ 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)
|
|
|
+ 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:
|
|
|
+ return response.json(14)
|
|
|
+
|
|
|
def do_update_interval(self, userID, request_dict, response):
|
|
|
uid = request_dict.get('uid', None)
|
|
|
interval = request_dict.get('interval', None)
|