|
@@ -30,6 +30,7 @@ from Object.ResponseObject import ResponseObject
|
|
|
from Object.TokenObject import TokenObject
|
|
|
from Object.UidTokenObject import UidTokenObject
|
|
|
from Service.CommonService import CommonService
|
|
|
+from Object.ETkObject import ETkObject
|
|
|
|
|
|
|
|
|
# http://192.168.136.40:8077/detect/changeStatus?uid=JW3684H8BSHG9TTM111A&token_val=18071adc03536302f34&appBundleId=com.ansjer.zccloud_ab&push_type=2&token=local&status=1&app_type=1&m_code=12
|
|
@@ -38,19 +39,19 @@ class DetectControllerView(View):
|
|
|
def dispatch(self, *args, **kwargs):
|
|
|
return super(DetectControllerView, self).dispatch(*args, **kwargs)
|
|
|
|
|
|
- def __init__(self):
|
|
|
- self.ip = ''
|
|
|
+ # def __init__(self):
|
|
|
+ # self.ip = ''
|
|
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
request.encoding = 'utf-8'
|
|
|
operation = kwargs.get('operation')
|
|
|
- self.ip = CommonService.get_ip_address(request)
|
|
|
+ # self.ip = CommonService.get_ip_address(request)
|
|
|
return self.validation(request.GET, operation)
|
|
|
|
|
|
def post(self, request, *args, **kwargs):
|
|
|
request.encoding = 'utf-8'
|
|
|
operation = kwargs.get('operation')
|
|
|
- self.ip = CommonService.get_ip_address(request)
|
|
|
+ # self.ip = CommonService.get_ip_address(request)
|
|
|
return self.validation(request.POST, operation)
|
|
|
|
|
|
def validation(self, request_dict, operation):
|
|
@@ -78,16 +79,21 @@ class DetectControllerView(View):
|
|
|
def do_query(self, request_dict, response, userID):
|
|
|
page = int(request_dict.get('page', None))
|
|
|
line = int(request_dict.get('line', None))
|
|
|
- nowTime = int(time.time())
|
|
|
if not page or not line:
|
|
|
return response.json(444, 'page,line')
|
|
|
-
|
|
|
- qs = Equipment_Info.objects.filter(userID_id=userID, addTime__gte=nowTime - 3600 * 24 * 27)
|
|
|
- uid = request_dict.get('uid', None)
|
|
|
- if uid:
|
|
|
- qs = qs.filter(devUid=uid)
|
|
|
- dvqs = Device_Info.objects.filter(UID=uid).values('Type', 'NickName')
|
|
|
- uid_type_dict = {uid: {'type': dvqs[0]['Type'], 'NickName': dvqs[0]['NickName']}}
|
|
|
+ startTime = request_dict.get('startTime', None)
|
|
|
+ endTime = request_dict.get('endTime', None)
|
|
|
+ qs = Equipment_Info.objects.filter(userID_id=userID)
|
|
|
+ if startTime and endTime:
|
|
|
+ qs = qs.filter(addTime__range=(startTime, endTime))
|
|
|
+ uids = request_dict.get('uids', None)
|
|
|
+ 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')
|
|
|
+ uid_type_dict = {}
|
|
|
+ for dv in dvqs:
|
|
|
+ uid_type_dict[dv['UID']] = {'type': dv['Type'], 'NickName': dv['NickName']}
|
|
|
else:
|
|
|
dvqs = Device_Info.objects.filter(userID_id=userID).values('UID', 'Type', 'NickName')
|
|
|
uid_type_dict = {}
|
|
@@ -97,7 +103,7 @@ class DetectControllerView(View):
|
|
|
if not qs.exists():
|
|
|
return response.json(0, {'datas': [], 'count': 0})
|
|
|
qs = qs.values('id', 'devUid', 'devNickName', 'Channel', 'eventType', 'status', 'alarm', 'eventTime',
|
|
|
- 'receiveTime', 'is_st')
|
|
|
+ 'receiveTime', 'is_st', 'addTime')
|
|
|
count = qs.count()
|
|
|
qr = qs[(page - 1) * line:page * line]
|
|
|
res = []
|
|
@@ -136,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)
|
|
@@ -247,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)
|
|
@@ -291,6 +395,14 @@ class NotificationView(View):
|
|
|
# return response.json(444)
|
|
|
utko = UidTokenObject(uidToken)
|
|
|
uid = utko.UID
|
|
|
+ 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:
|
|
|
+ # 设置推送间隔60秒一次
|
|
|
+ redisObj.set_data(key=pkey, val=1, expire=60)
|
|
|
uid_set_qs = UidSetModel.objects.filter(uid=uid, detect_status=1)
|
|
|
if uid_set_qs.exists():
|
|
|
uid_set_id = uid_set_qs[0].id
|
|
@@ -300,16 +412,7 @@ class NotificationView(View):
|
|
|
uid_push_qs = UidPushModel.objects.filter(uid_set__id=uid_set_id). \
|
|
|
values('token_val', 'app_type', 'appBundleId', 'push_type', 'userID_id', 'userID__NickName', 'lang',
|
|
|
'tz')
|
|
|
- if uid_set_qs.exists():
|
|
|
- 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 = uid_set_qs[0].detect_interval
|
|
|
- if detect_interval:
|
|
|
- redisObj.set_data(key=pkey, val=1, expire=detect_interval)
|
|
|
+ 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')
|
|
|
for up in uid_push_qs:
|
|
@@ -498,10 +601,9 @@ class NotificationView(View):
|
|
|
return False
|
|
|
|
|
|
|
|
|
-# http://192.168.136.40:8077/notify/push?uidToken=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1aWQiOiJUTjdNUEUzMjExVUU3NkFQMTExQSJ9.k501567VdnhFpn_ygzGRDat3Kqlz5CsEA9jAC2dDk_g&obj=12341234&n_time=1234561234
|
|
|
-# http://test.dvema.com/notify/push?uidToken=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiJQMldOR0pSRDJFSEE1RVU5MTExQSJ9.xOCI5lerk8JOs5OcAzunrKCfCrtuPIZ3AnkMmnd-bPY&n_time=1526845794&channel=1&event_type=51&is_st=0
|
|
|
+# http://test.dvema.com/detect/add?uidToken=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiJQMldOR0pSRDJFSEE1RVU5MTExQSJ9.xOCI5lerk8JOs5OcAzunrKCfCrtuPIZ3AnkMmnd-bPY&n_time=1526845794&channel=1&event_type=51&is_st=0
|
|
|
# 移动侦测接口
|
|
|
-class NotificationViewXX(View):
|
|
|
+class PushNotificationView(View):
|
|
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
request.encoding = 'utf-8'
|
|
@@ -514,8 +616,74 @@ class NotificationViewXX(View):
|
|
|
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)
|
|
|
- return
|
|
|
+ event_type = request_dict.get('event_type', None)
|
|
|
+ is_st = request_dict.get('is_st', None)
|
|
|
+ eto = ETkObject(etk)
|
|
|
+ uid = eto.uid
|
|
|
+ if len(uid) == 20:
|
|
|
+ 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:
|
|
|
+ redisObj.set_data(key=pkey, val=1, expire=60)
|
|
|
+ uid_set_qs = UidSetModel.objects.filter(uid=uid, detect_status=1)
|
|
|
+ if uid_set_qs.exists():
|
|
|
+ uid_set_id = uid_set_qs[0].id
|
|
|
+ uid_push_qs = UidPushModel.objects.filter(uid_set__id=uid_set_id). \
|
|
|
+ values('token_val', 'app_type', 'appBundleId', 'push_type',
|
|
|
+ 'userID_id', 'userID__NickName', 'lang', 'tz')
|
|
|
+ if uid_set_qs.exists():
|
|
|
+ auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
|
|
|
+ bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
|
|
|
+ self.do_bulk_create_info(uid_push_qs, n_time, channel, event_type, is_st, uid)
|
|
|
+ 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:
|
|
|
+ return JsonResponse(status=200, data={'code': 404, 'msg': 'data is not exist'})
|
|
|
+ else:
|
|
|
+ return JsonResponse(status=200, data={'code': 404, 'msg': 'data is not exist'})
|
|
|
+ else:
|
|
|
+ return JsonResponse(status=200, data={'code': 404, 'msg': 'wrong etk'})
|
|
|
+
|
|
|
+ def do_bulk_create_info(self, uaqs, n_time, channel, event_type, is_st, uid):
|
|
|
+ #
|
|
|
+ qs_list = []
|
|
|
+ nowTime = int(time.time())
|
|
|
+ # 设备昵称
|
|
|
+ userID_ids = []
|
|
|
+ for dv in uaqs:
|
|
|
+ userID_id = dv["userID_id"]
|
|
|
+ if userID_id not in userID_ids:
|
|
|
+ add_data = {
|
|
|
+ 'userID_id': dv["userID_id"],
|
|
|
+ 'eventTime': n_time,
|
|
|
+ 'eventType': event_type,
|
|
|
+ 'devUid': uid,
|
|
|
+ 'devNickName': uid,
|
|
|
+ 'Channel': channel,
|
|
|
+ 'alarm': 'Motion \tChannel:{channel}'.format(channel=channel),
|
|
|
+ 'is_st': int(is_st),
|
|
|
+ 'receiveTime': n_time,
|
|
|
+ 'addTime': nowTime
|
|
|
+ }
|
|
|
+ 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:
|
|
|
+ return False
|