DvrController.java
2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package com.bsth.controller;
import com.bsth.common.ResponseCode;
import com.bsth.data.SystemParamCache;
import com.bsth.util.HttpClientUtils;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.*;
@RestController
@RequestMapping("dvr")
public class DvrController {
private final static Logger log = LoggerFactory.getLogger(DvrController.class);
@Autowired
private ObjectMapper mapper;
@RequestMapping(value = "/jt1078")
public Map<String, Object> jt1078(@RequestParam("sim") String sim, @RequestParam("channel") int channel) {
Map<String, Object> result = new HashMap<>();
result.put("status", ResponseCode.ERROR);
result.put("msg", "未获取到视频播放地址");
try {
if (StringUtils.isEmpty(sim)) {
result.put("msg", "sim为空");
throw new IllegalArgumentException("无效的sim");
}
if (channel < 1 || channel > 10) {
result.put("msg", "无效的通道号");
throw new IllegalArgumentException("无效的通道号");
}
sim = sim.replaceAll("^0*", "");
String url = SystemParamCache.getUrlHttpWvpPlay();
url = String.format(url, sim, channel);
Map<String, Object> header = new HashMap<>();
header.put("access-token", SystemParamCache.getTokenHttpWvp());
StringBuilder sb = HttpClientUtils.post(url, "{}", header);
if (sb != null) {
Map<String, Object> response = mapper.readValue(sb.toString(), Map.class);
if ((Integer) response.get("code") == 0) {
Map<String, Object> data = mapper.readValue(mapper.writeValueAsString(response.get("data")), Map.class);
result.put("status", ResponseCode.SUCCESS);
result.put("data", data);
}
result.put("msg", response.get("msg"));
}
} catch (Exception e) {
result.put("status", ResponseCode.ERROR);
if (result.get("msg") == null) {
result.put("msg", "捕获到异常,检查日志信息");
}
log.error(e.getMessage(), e);
}
return result;
}
}