From b88ed488e7802f0ba349556313813c69f355eeab Mon Sep 17 00:00:00 2001 From: "Mr.Wang" Date: Mon, 29 Jul 2024 16:53:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=8E=B7=E5=8F=96=E8=A7=86?= =?UTF-8?q?=E9=A2=91=E6=B5=81=E6=8E=A5=E5=8F=A3=E9=94=99=E8=AF=AF=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../business/controller/VideoController.java | 78 ++++++++++--------- 1 file changed, 43 insertions(+), 35 deletions(-) diff --git a/zc-business/src/main/java/com/zc/business/controller/VideoController.java b/zc-business/src/main/java/com/zc/business/controller/VideoController.java index 609d51ab..4da078c9 100644 --- a/zc-business/src/main/java/com/zc/business/controller/VideoController.java +++ b/zc-business/src/main/java/com/zc/business/controller/VideoController.java @@ -442,7 +442,7 @@ public class VideoController extends BaseController { */ @ApiOperation("获取视频流信息") @GetMapping(value = "/externalVideoStreaming") - public JSONObject externalVideoStreaming(@ApiParam(value = "摄像头标识", name = "camId", required = true) String camId) throws HttpException, IOException { + public JSONObject externalVideoStreaming(@ApiParam(value = "摄像头标识", name = "camId", required = true) String camId) { JSONObject cameraInfo = JSONObject.parseObject(configService.selectConfigByKey("dc.cameraInfo")); JSONObject jsonResult = null; @@ -453,48 +453,56 @@ public class VideoController extends BaseController { requestParams.put("type", UniversalEnum.ONE.getValue()); requestParams.put("camId", camId); - Map header = new HashMap<>(); - - if (VideoController.TOKEN == null) { - getToken(); - } - - header.put("Authorization", TOKEN); - - Response response // 请求响应 - = okHttp - .headers(header) - .url(cameraInfo.getString("URL") + UniversalEnum.GET_VIDEO_STREAM_INFORMATION.getValue()) // 请求地址 - .data(requestParams) // 请求参数 - .post(); // 请求方法 + try { + Map header = new HashMap<>(); - if (response.body() != null) { - jsonResult = JSONObject.parseObject(response.body().string()); + if (VideoController.TOKEN == null) { + getToken(); + } - if (jsonResult.containsKey("code")) { - if (HttpStatus.SUCCESS == jsonResult.getInteger("code")) { - Map data = jsonResult.getJSONObject("data"); - String liveUrl = data.get("liveUrl").toString(); - liveUrl = configService.selectConfigByKey("dc.cameraUrl") + liveUrl.substring(UniversalEnum.SEVEN.getNumber()); - data.put("liveUrl",liveUrl); - jsonResult.put("data",data); - } else if (UNAUTHORIZED.equals(jsonResult.getInteger("code"))) { - getToken(); - okHttp.post(); - if (response.body() != null) { - jsonResult = JSONObject.parseObject(response.body().string()); - if (HttpStatus.SUCCESS == jsonResult.getInteger("code")) { - Map data = jsonResult.getJSONObject("data"); - String liveUrl = data.get("liveUrl").toString(); - liveUrl = configService.selectConfigByKey("cameraUrl") + liveUrl.substring(UniversalEnum.SEVEN.getNumber()); - data.put("liveUrl",liveUrl); - jsonResult.put("data",data); + header.put("Authorization", TOKEN); + + Response response // 请求响应 + = okHttp + .headers(header) + .url(cameraInfo.getString("URL") + UniversalEnum.GET_VIDEO_STREAM_INFORMATION.getValue()) // 请求地址 + .data(requestParams) // 请求参数 + .post(); // 请求方法 + + if (response.body() != null) { + jsonResult = JSONObject.parseObject(response.body().string()); + + if (jsonResult.containsKey("code")) { + if (HttpStatus.SUCCESS == jsonResult.getInteger("code")) { + Map data = jsonResult.getJSONObject("data"); + String liveUrl = data.get("liveUrl").toString(); + liveUrl = configService.selectConfigByKey("dc.cameraUrl") + liveUrl.substring(UniversalEnum.SEVEN.getNumber()); + data.put("liveUrl",liveUrl); + jsonResult.put("data",data); + } else if (UNAUTHORIZED.equals(jsonResult.getInteger("code"))) { + getToken(); + okHttp.post(); + if (response.body() != null) { + jsonResult = JSONObject.parseObject(response.body().string()); + if (HttpStatus.SUCCESS == jsonResult.getInteger("code")) { + Map data = jsonResult.getJSONObject("data"); + String liveUrl = data.get("liveUrl").toString(); + liveUrl = configService.selectConfigByKey("cameraUrl") + liveUrl.substring(UniversalEnum.SEVEN.getNumber()); + data.put("liveUrl",liveUrl); + jsonResult.put("data",data); + } } } } } + }catch (Exception e) { + jsonResult = new JSONObject(); + jsonResult.put("code",200); + jsonResult.put("data", new JSONObject()); + jsonResult.put("msg","摄像机连接失败"); } + return jsonResult; }