|
@@ -89,31 +89,12 @@ class loginHandleView(TemplateView):
|
|
res_json = res.json()
|
|
res_json = res.json()
|
|
if res_json['result_code'] == 0:
|
|
if res_json['result_code'] == 0:
|
|
userID = res_json['result']['userID']
|
|
userID = res_json['result']['userID']
|
|
- uid_arr = res_json['result']['uid_arr']
|
|
|
|
|
|
+ # uid_arr = res_json['result']['uid_arr']
|
|
nowTime = int(time.time())
|
|
nowTime = int(time.time())
|
|
user_qs = UserModel.objects.filter(userID=userID)
|
|
user_qs = UserModel.objects.filter(userID=userID)
|
|
if not user_qs.exists():
|
|
if not user_qs.exists():
|
|
- user_qs = UserModel.objects.create(userID=userID, addTime=nowTime, updTime=nowTime)
|
|
|
|
- userID = user_qs.userID
|
|
|
|
|
|
+ UserModel.objects.create(userID=userID, addTime=nowTime, updTime=nowTime)
|
|
user_qs = UserModel.objects.filter(userID=userID)
|
|
user_qs = UserModel.objects.filter(userID=userID)
|
|
- else:
|
|
|
|
- userID = user_qs[0].userID
|
|
|
|
- querysetlist = []
|
|
|
|
- rtko = tkObject(rank=1)
|
|
|
|
- UidRtspModel.objects.filter(user_id=userID).delete()
|
|
|
|
- for uid_a in uid_arr:
|
|
|
|
- rtsp_url = rtko.encrypt(data=uid_a['uid'])
|
|
|
|
- create_data = {
|
|
|
|
- 'uid': uid_a['uid'],
|
|
|
|
- 'password': uid_a['password'],
|
|
|
|
- 'nick': uid_a['nick'],
|
|
|
|
- 'addTime': nowTime,
|
|
|
|
- 'updTime': nowTime,
|
|
|
|
- 'user_id': userID,
|
|
|
|
- 'rtsp_url': rtsp_url,
|
|
|
|
- }
|
|
|
|
- querysetlist.append(UidRtspModel(**create_data))
|
|
|
|
- UidRtspModel.objects.bulk_create(querysetlist)
|
|
|
|
code = CommonService.encrypt_data(32)
|
|
code = CommonService.encrypt_data(32)
|
|
user_qs.update(code=code)
|
|
user_qs.update(code=code)
|
|
redirect_uri = redirect_uri + '?code=' + code + '&state=' + state
|
|
redirect_uri = redirect_uri + '?code=' + code + '&state=' + state
|
|
@@ -201,8 +182,9 @@ class oa2RtspStartView(TemplateView):
|
|
user_qs = UserModel.objects.filter(access_token=access_token)
|
|
user_qs = UserModel.objects.filter(access_token=access_token)
|
|
if user_qs.exists():
|
|
if user_qs.exists():
|
|
print('select by mysql data')
|
|
print('select by mysql data')
|
|
- userID = user_qs[0].userID
|
|
|
|
- ur_qs = UidRtspModel.objects.filter(user_id=userID, uid=id).values('uid', 'nick', 'rtsp_url', 'password')
|
|
|
|
|
|
+ # userID = user_qs[0].userID
|
|
|
|
+ ur_qs = UidRtspModel.objects.filter(uid=id).values('uid', 'nick', 'rtsp_url', 'password')
|
|
|
|
+ # ur_qs = UidRtspModel.objects.filter(usermodel__userID=userID,uid=)
|
|
UID = ur_qs[0]['uid']
|
|
UID = ur_qs[0]['uid']
|
|
PWD = ur_qs[0]['password']
|
|
PWD = ur_qs[0]['password']
|
|
MSG = 'rtsp://rtsp.zositech.xyz:8554/{stream_name}'.format(stream_name=ur_qs[0]['rtsp_url'])
|
|
MSG = 'rtsp://rtsp.zositech.xyz:8554/{stream_name}'.format(stream_name=ur_qs[0]['rtsp_url'])
|
|
@@ -256,72 +238,43 @@ class oa2DiscoveryDevice(TemplateView):
|
|
request_dict = request.GET
|
|
request_dict = request.GET
|
|
return self.validate(request_dict)
|
|
return self.validate(request_dict)
|
|
|
|
|
|
- def validate1(self, request_dict):
|
|
|
|
- # 增加对code和client_id的校验代码,返回access_token和refresh_token
|
|
|
|
- access_token = request_dict.get("access_token", None)
|
|
|
|
- user_qs = UserModel.objects.filter(access_token=access_token)
|
|
|
|
- response = ResObject()
|
|
|
|
- if user_qs.exists():
|
|
|
|
- userID = user_qs[0].userID
|
|
|
|
- ur_qs = UidRtspModel.objects.filter(user_id=userID).values('uid', 'nick', 'rtsp_url', 'id')
|
|
|
|
-
|
|
|
|
- if ur_qs.exists():
|
|
|
|
- res_json = []
|
|
|
|
- for ur in ur_qs:
|
|
|
|
- ur_data = {
|
|
|
|
- 'endpointId': ur['id'],
|
|
|
|
- 'manufacturerName': 'Axis',
|
|
|
|
- 'manufacturerId': 'axis-ACCC8E5E7513',
|
|
|
|
- 'modelName': 'P1425-LE',
|
|
|
|
- 'friendlyName': 'Camera {nick}'.format(nick=ur['nick']),
|
|
|
|
- 'description': 'Camera {nick}'.format(nick=ur['nick']),
|
|
|
|
- 'resolutions': [{'width': 1280, 'height': 720}],
|
|
|
|
- 'videoCodecs': ['H264'],
|
|
|
|
- 'audioCodecs': ['ACC'],
|
|
|
|
- 'protocols': ['RTSP'],
|
|
|
|
- 'authorizationTypes': ['NONE'],
|
|
|
|
- 'uri': 'rtsp://rtsp.zositech.xyz:443/{stream_name}'.format(stream_name=ur['rtsp_url'])
|
|
|
|
- }
|
|
|
|
- res_json.append(ur_data)
|
|
|
|
- return JsonResponse(res_json, safe=False)
|
|
|
|
- # return response.json(0, res_json)
|
|
|
|
- else:
|
|
|
|
- return response.json(0, 'data is none~')
|
|
|
|
- else:
|
|
|
|
- return JsonResponse({'res': '11'})
|
|
|
|
-
|
|
|
|
def validate(self, request_dict):
|
|
def validate(self, request_dict):
|
|
# 增加对code和client_id的校验代码,返回access_token和refresh_token
|
|
# 增加对code和client_id的校验代码,返回access_token和refresh_token
|
|
access_token = request_dict.get("access_token", None)
|
|
access_token = request_dict.get("access_token", None)
|
|
- user_qs = UserModel.objects.filter(access_token=access_token)
|
|
|
|
- response = ResObject()
|
|
|
|
- if user_qs.exists():
|
|
|
|
- userID = user_qs[0].userID
|
|
|
|
- # =====================
|
|
|
|
|
|
+ try:
|
|
|
|
+ user_qs = UserModel.objects.get(access_token=access_token)
|
|
|
|
+ except Exception as e:
|
|
|
|
+ return JsonResponse({'res': '11'})
|
|
|
|
+ else:
|
|
|
|
+ response = ResObject()
|
|
|
|
+ userID = user_qs.userID
|
|
auth_request_url = '{SERVER_PREFIX}/oalexa/discoveryuid'.format(SERVER_PREFIX=SERVER_PREFIX)
|
|
auth_request_url = '{SERVER_PREFIX}/oalexa/discoveryuid'.format(SERVER_PREFIX=SERVER_PREFIX)
|
|
requests_data = {'sid': 'admin', 'sst': 'admin', 'alexa_user_id': userID}
|
|
requests_data = {'sid': 'admin', 'sst': 'admin', 'alexa_user_id': userID}
|
|
res = requests.post(url=auth_request_url, data=requests_data)
|
|
res = requests.post(url=auth_request_url, data=requests_data)
|
|
print(res.json())
|
|
print(res.json())
|
|
- print(res.json()['result_code'])
|
|
|
|
res_json = res.json()
|
|
res_json = res.json()
|
|
if res_json['result_code'] == 0:
|
|
if res_json['result_code'] == 0:
|
|
uid_arr = res_json['result']['uid_arr']
|
|
uid_arr = res_json['result']['uid_arr']
|
|
- now_time = int(time.time())
|
|
|
|
- querysetlist = []
|
|
|
|
rtko = tkObject(rank=1)
|
|
rtko = tkObject(rank=1)
|
|
- UidRtspModel.objects.filter(user_id=userID).delete()
|
|
|
|
|
|
+ now_time = int(time.time())
|
|
|
|
+ user_qs.uid_rtsp.clear()
|
|
res_json = []
|
|
res_json = []
|
|
|
|
+ uid_rtsp_id_list = []
|
|
for uid_a in uid_arr:
|
|
for uid_a in uid_arr:
|
|
- rtsp_url = rtko.encrypt(data=uid_a['uid'])
|
|
|
|
- querysetlist.append(UidRtspModel(
|
|
|
|
- uid=uid_a['uid'],
|
|
|
|
- password=uid_a['password'],
|
|
|
|
- nick=uid_a['nick'],
|
|
|
|
- addTime=now_time,
|
|
|
|
- updTime=now_time,
|
|
|
|
- user_id=userID,
|
|
|
|
- rtsp_url=rtsp_url,
|
|
|
|
- ))
|
|
|
|
|
|
+ uid = uid_a['uid']
|
|
|
|
+ rtsp_url = rtko.encrypt(data=uid)
|
|
|
|
+ try:
|
|
|
|
+ uid_rtsp_qs = UidRtspModel.objects.get(uid=uid)
|
|
|
|
+ except UidRtspModel.DoesNotExist:
|
|
|
|
+ uid_rtsp_qs = UidRtspModel.objects.create(
|
|
|
|
+ uid=uid_a['uid'],
|
|
|
|
+ password=uid_a['password'],
|
|
|
|
+ nick=uid_a['nick'],
|
|
|
|
+ addTime=now_time,
|
|
|
|
+ updTime=now_time,
|
|
|
|
+ rtsp_url=rtsp_url,
|
|
|
|
+ )
|
|
|
|
+ uid_rtsp_id_list.append(uid_rtsp_qs.id)
|
|
ur_data = {
|
|
ur_data = {
|
|
'endpointId': uid_a['uid'],
|
|
'endpointId': uid_a['uid'],
|
|
'manufacturerName': 'Axis',
|
|
'manufacturerName': 'Axis',
|
|
@@ -337,12 +290,11 @@ class oa2DiscoveryDevice(TemplateView):
|
|
'uri': 'rtsp://rtsp.zositech.xyz:443/{stream_name}'.format(stream_name=rtsp_url)
|
|
'uri': 'rtsp://rtsp.zositech.xyz:443/{stream_name}'.format(stream_name=rtsp_url)
|
|
}
|
|
}
|
|
res_json.append(ur_data)
|
|
res_json.append(ur_data)
|
|
- UidRtspModel.objects.bulk_create(querysetlist)
|
|
|
|
|
|
+ print(uid_rtsp_id_list)
|
|
|
|
+ user_qs.uid_rtsp.add(*uid_rtsp_id_list)
|
|
return JsonResponse(res_json, safe=False)
|
|
return JsonResponse(res_json, safe=False)
|
|
else:
|
|
else:
|
|
return response.json(0, res={'msg': 'error'})
|
|
return response.json(0, res={'msg': 'error'})
|
|
- else:
|
|
|
|
- return JsonResponse({'res': '11'})
|
|
|
|
|
|
|
|
|
|
|
|
'''
|
|
'''
|