|
@@ -42,7 +42,6 @@ class deviceStatus(TemplateView):
|
|
|
|
|
|
def post(self, request, *args, **kwargs):
|
|
|
logger = logging.getLogger('django')
|
|
|
- logger.info('post----------------------------------------')
|
|
|
request.encoding = 'utf-8'
|
|
|
operation = kwargs.get('operation')
|
|
|
return self.validation(request.POST, request, operation)
|
|
@@ -54,16 +53,11 @@ class deviceStatus(TemplateView):
|
|
|
if operation == 'saveAccessToken':
|
|
|
return self.saveAccessToken(request_dict, response)
|
|
|
if operation == 'addOrUpdate':
|
|
|
- logger = logging.getLogger('django')
|
|
|
- logger.info('in__________________________validation________')
|
|
|
-
|
|
|
return self.addOrUpdate(request_dict, response)
|
|
|
if operation == 'delete':
|
|
|
return self.delete(request_dict, response)
|
|
|
- elif operation == 'test':
|
|
|
- return self.discover(request_dict, response)
|
|
|
- logger = logging.getLogger('django')
|
|
|
- logger.info('in__________________________validation________')
|
|
|
+ if operation == 'stopPush':
|
|
|
+ return self.notifiesDeviceStopPush(request_dict, response)
|
|
|
def saveAccessToken(self,request_dict, response):
|
|
|
access_token = request_dict.get("access_token", '')
|
|
|
refresh_token = request_dict.get("refresh_token", '')
|
|
@@ -92,6 +86,7 @@ class deviceStatus(TemplateView):
|
|
|
)
|
|
|
return JsonResponse({'code':200,'msg':'success'})
|
|
|
|
|
|
+ #向alex事件网关发送更新设备操作
|
|
|
def addOrUpdate(self,request_dict, response):
|
|
|
logger = logging.getLogger('django')
|
|
|
logger.info('in__________________________first')
|
|
@@ -189,6 +184,7 @@ class deviceStatus(TemplateView):
|
|
|
|
|
|
# return json.dumps('test',indent=4,sort_keys=True,ensure_ascii=False) #格式化返回内容
|
|
|
|
|
|
+ #向alex事件网关发送删除设备操作
|
|
|
def delete(self,request_dict, response):
|
|
|
UID = request_dict.get("UID", '')
|
|
|
userID = request_dict.get("userID", '')
|
|
@@ -275,6 +271,83 @@ class deviceStatus(TemplateView):
|
|
|
return request_json
|
|
|
|
|
|
|
|
|
+ def notifiesDeviceStopPush(self,request_dict, response):
|
|
|
+ play_url = "http://rtsp.zositech.org:10008/api/v1/players"
|
|
|
+ push_url = "http://rtsp.zositech.org:10008/api/v1/pushers"
|
|
|
+ try:
|
|
|
+ queryPlay = requests.get(url=play_url, timeout=5)
|
|
|
+ qplay = queryPlay.json()
|
|
|
+
|
|
|
+ queryPush = requests.get(url=push_url, timeout=5)
|
|
|
+ qpush = queryPush.json()
|
|
|
+ except Exception as e:
|
|
|
+ return response.json(103, res='query fail')
|
|
|
+ else:
|
|
|
+ # response.json(103, res=list(qplay))
|
|
|
+ #正在拉流的ID
|
|
|
+ play_rows = qplay['rows']
|
|
|
+ play_paths = []
|
|
|
+ for val in play_rows:
|
|
|
+ play_paths.append(val['path'])
|
|
|
+
|
|
|
+ #正在推流的ID
|
|
|
+ push_rows = qpush['rows']
|
|
|
+ push_paths = []
|
|
|
+ for val in push_rows:
|
|
|
+ startAt = self.str_to_timestamp(val['startAt'])
|
|
|
+ run_time = int(time.time()) - int(startAt)
|
|
|
+ if run_time > 5*60:
|
|
|
+ push_paths.append(val['path'])
|
|
|
+ send_flag = False
|
|
|
+ #正在推流但是没有拉流的推流通知设备断掉
|
|
|
+ for push_path in push_paths:
|
|
|
+ if push_path not in play_paths:
|
|
|
+ path_list = push_path.split('/')
|
|
|
+ has_rtsp_url = UidRtspModel.objects.filter(rtsp_url=path_list[-1]).values('uid','password')
|
|
|
+ # has_rtsp_url = UidRtspModel.objects.filter(rtsp_url='RFJrWk9OVVJPUVRnM1IxaFNXazFFUXpFeE1VRT1U').values('uid')
|
|
|
+ if has_rtsp_url.exists():
|
|
|
+ send_flag = self.runSendStop(has_rtsp_url[0]['uid'], has_rtsp_url[0]['password'], push_path)
|
|
|
+ print(send_flag)
|
|
|
+ exit()
|
|
|
+ if send_flag:
|
|
|
+ return JsonResponse({'res':'success'})
|
|
|
+ else:
|
|
|
+ return JsonResponse({'res':'fail'})
|
|
|
+
|
|
|
+
|
|
|
+ #把格式化时间转换成时间戳
|
|
|
+ def str_to_timestamp(self, str_time=None, format='%Y-%m-%d %H:%M:%S'):
|
|
|
+ if str_time:
|
|
|
+ time_tuple = time.strptime(str_time, format) # 把格式化好的时间转换成元祖
|
|
|
+ result = time.mktime(time_tuple) # 把时间元祖转换成时间戳
|
|
|
+ return int(result)
|
|
|
+ return int(time.time())
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ #触发此方法,让摄像头推流到MSG流地址
|
|
|
+ def runSendStop(self, UID, PWD, MSG):
|
|
|
+
|
|
|
+ command = "./pushtool {UID} {PWD} {MSG} 0".format(UID=UID, PWD=PWD, MSG=MSG)
|
|
|
+ # print('command=>{command}'.format(command=command))
|
|
|
+ command_url = "http://47.115.134.251/index.php?command={command}".format(command=command)
|
|
|
+ try:
|
|
|
+ exec_res = requests.get(url=command_url, timeout=2)
|
|
|
+ res = exec_res.json()
|
|
|
+ if res['code'] == 200:
|
|
|
+ return True
|
|
|
+ except Exception as e:
|
|
|
+ return False
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
#请求alexa事件网关接口失败错误码
|
|
|
'''
|