DvrController.java
1.75 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
package com.bsth.controller;
import com.bsth.common.SystemParamKeys;
import com.bsth.data.SystemParamCache;
import com.bsth.security.util.SecurityUtils;
import com.bsth.util.WebserviceSign;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@RestController
@RequestMapping("dvr")
public class DvrController {
private final static Logger log = LoggerFactory.getLogger(DvrController.class);
@RequestMapping(value = "/{deviceId}/redirect", method = RequestMethod.GET)
public void getLineCode(@PathVariable("deviceId") String deviceId, HttpServletResponse response) {
try {
String url = SystemParamCache.getUrlHttpDvr(), password = SystemParamCache.getUrlHttpDvrPwd(), nonce = WebserviceSign.getRandomString(5);
String userName = SecurityUtils.getCurrentUser().getJobCode(), timestamp = String.valueOf(System.currentTimeMillis());
Map<String, String> params = new HashMap<>();
params.put("timestamp", timestamp);
params.put("nonce", nonce);
params.put("password", password);
params.put("username", userName);
String sign = WebserviceSign.getSHA1(params);
url = String.format(url, timestamp, nonce, password, userName, sign, deviceId);
log.error("dvr url: {}", url);
response.sendRedirect(url);
} catch (IOException e) {
throw new RuntimeException(e);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}