Browse Source

修改获取视频流接口错误处理

develop
Mr.Wang 4 months ago
parent
commit
b88ed488e7
  1. 78
      zc-business/src/main/java/com/zc/business/controller/VideoController.java

78
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<String, String> 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<String, String> 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<String,Object> 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<String,Object> 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<String,Object> 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<String,Object> 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;
}

Loading…
Cancel
Save