DvrController.java 1.75 KB
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);
        }
    }
}