HikVersionController.java
4.1 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package com.skua.modules.app.video;
import com.alibaba.fastjson.JSONObject;
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
import com.hikvision.artemis.sdk.config.ArtemisConfig;
import com.skua.core.aspect.annotation.AutoLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.Map;
@Slf4j
@Api(tags="海康威视视频流地址获取")
@RestController
@RequestMapping("/app/video/hikVideo")
public class HikVersionController {
@AutoLog(value = "地址")
@ApiOperation(value="地址", notes="地址")
@PostMapping(value = "/previewURL")
public JSONObject GetCameraPreviewURL(@RequestBody Map<String,String> map) {
//String code, String url, String protocol,String streamform
if (map.isEmpty()){
return null;
}
String code = map.get("code");
String url = map.get("url");
if (StringUtils.isBlank(url)){
url = "106.225.156.168:8667";
}
String protocol = map.get("protocol");
String streamform = map.get("streamform");
/**
* STEP1:设置平台参数,根据实际情况,设置host appkey appsecret 三个参数.
*/
//ArtemisConfig.host = "189.200.0.86:8667"; // artemis网关服务器ip端口
//ArtemisConfig.host = "106.225.156.168:8667"; // artemis网关服务器ip端口
ArtemisConfig.host = url; // artemis网关服务器ip端口
ArtemisConfig.appKey = "27232944"; // 秘钥appkey
ArtemisConfig.appSecret = "jZJacfeacQmK6Bn9iOHe";// 秘钥appSecret
/**
* STEP2:设置OpenAPI接口的上下文
*/
final String ARTEMIS_PATH = "/artemis";
/**
* STEP3:设置接口的URI地址
*/
final String previewURLsApi = ARTEMIS_PATH + "/api/video/v1/cameras/previewURLs";
Map<String, String> path = new HashMap<String, String>(2) {
{
put("https://", previewURLsApi);//根据现场环境部署确认是http还是https
}
};
/**
* STEP4:设置参数提交方式
*/
String contentType = "application/json";
/**
* STEP5:组装请求参数
*/
JSONObject jsonBody = new JSONObject();
jsonBody.put("protocol", protocol);
jsonBody.put("expand", "streamform="+streamform);
//jsonBody.put("cameraIndexCode", "f570f0fc5cbc4904b3634e4fb8771dc0,5a96159594ff44ad86a00f43795f458a");bde554256a344764be61573cc2dd3ed9
jsonBody.put("cameraIndexCode", code);
jsonBody.put("streamType", 0);
//jsonBody.put("protocol", "ws");
jsonBody.put("transmode", 1);
//jsonBody.put("expand", "streamform=ps");
String body = jsonBody.toJSONString();
/**
* STEP6:调用接口
*/
String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType , null);// post请求application/json类型参数
JSONObject jsonObject = null;
if (!"".equals(result)&&result!=null){
jsonObject = JSONObject.parseObject(result);
}
return jsonObject;
}
//public static void main(String[] args) {
//
// JSONObject jsonObject1 = new HikVersionController().GetCameraPreviewURL("5a96159594ff44ad86a00f43795f458a","");
// JSONObject jsonObject2 = new HikVersionController().GetCameraPreviewURL("5ea4697ee3744365953ccf6f70b808fa","");
// //JSONObject jsonObject1 = new HikVersionController().GetCameraPreviewURL("4c48ac7ffce44dcea75a9785effaf317");
// //JSONObject jsonObject2 = new HikVersionController().GetCameraPreviewURL("4807adcf1efd4a45a50e91a4875a3882");
// System.out.println("result结果示例: " + jsonObject1);
// System.out.println("result结果示例: " + jsonObject2);
//}
}