/*企业视频监控及回放
* equipmentId=E61616319
*type=1 (1是实时,2是回放,回访需要输入开始时间和结束时间)
* startTime=2023-02-12 00:00:00
* stopTime=2023-02-12 23:59:59
* */
@PostMapping("/vedioBack")
@ResponseBody
public String vedioBack(VideoMonitoring videoMonitoring){
String equipmentId = videoMonitoring.getEquipmentId();
String type = videoMonitoring.getType();
String startTime = videoMonitoring.getStartTime();
String stopTime = videoMonitoring.getStopTime();
String head="https://open.ys7.com/ezopen/h5/iframe?url=";
String url="";
String accessToken=getVideoToken();
if (startTime!=null){
url="https://open.ys7.com/api/lapp/v2/live/address/get?accessToken=" + accessToken +"&deviceSerial="+equipmentId + "&type="+ type+
"&startTime=" + startTime + "&stopTime=" + stopTime;
}else {
url="https://open.ys7.com/api/lapp/v2/live/address/get?accessToken=" + accessToken +"&deviceSerial="+equipmentId + "&type="+ type;
}
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.add("Content-Type","application/x-www-form-urlencoded");
RestTemplate restTemplate = new RestTemplate();
HttpEntity requestEntity = new HttpEntity<>(httpHeaders);
ResponseEntity<JSONObject> responseEntity = restTemplate.postForEntity(url, requestEntity, JSONObject.class);
JSONObject data = responseEntity.getBody().getJSONObject("data");
String url1 = data.getString("url");
String result=head+url1+"&accessToken="+accessToken;
return result;
}
/**
* 获取监控token,过期时间为七天
*/
public String getVideoToken() {
String url = "https://open.ys7.com/api/lapp/token/get";
String params = "appKey=123456";
String result = "";
try {
String s = HttpUtils.sendPost2(url, params);
JSONObject jsonObject = JSONObject.parseObject(s);
String code = (String) jsonObject.get("code");
String msg = (String) jsonObject.get("msg");
Map<String, String> data = (Map<String, String>) jsonObject.get("data");
String accessToken = data.get("accessToken");
if ("200".equals(code)) {
result = accessToken;
} else {
result = "-1";//获取token错误
}
} catch (Exception e) {
e.printStackTrace();
}
return result ;
}