11
zhanghua
2024-09-05 a77cd2572fae653df15a202bdcd692a8e9c44a04
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
package com.example.demo;
 
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
import com.hikvision.artemis.sdk.config.ArtemisConfig;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
 
import java.util.HashMap;
import java.util.Map;
 
@SpringBootApplication
public class DemoApplication {
 
    public static void main(String[] args) {
 
        SpringApplication.run(DemoApplication.class, args);
 
//        String result = null;
//        try {
//            result = getKHVideo("33112351001320000255");
//        } catch (Exception e) {
//            throw new RuntimeException(e);
//        }
//        System.out.println(result);
 
    }
 
    private static final String ARTEMIS_PATH = "/artemis";
 
    public static String getKHVideo(String code) throws Exception {
 
        ArtemisConfig config = new ArtemisConfig();
        config.setHost("10.53.133.82:1443"); // 代理API网关nginx服务器ip端口
        config.setAppKey("29967737");  // 秘钥appkey
        config.setAppSecret("LElVf9Ct3ykStZHCmFNZ");// 秘钥appSecret
        final String getSecurityApi = ARTEMIS_PATH + "/api/video/v1/cameras/previewURLs"; // 接口路径
//        System.out.println("请求设备号:" + code);
        Map<String, String> path = new HashMap<String, String>(2) {
            {
                put("https://", getSecurityApi);
            }
        };
        Map<String, String> head = new HashMap<String, String>(2) {  //get请求的head参数
            {
                put("headpost", "sky-test");
            }
        };
        Map<String, String> query = new HashMap<String, String>(2) {  //get请求的head参数
            {
                put("domainId", "0");
            }
        };
        JSONObject jsonBody = new JSONObject();
        jsonBody.put("cameraIndexCode", code);
        jsonBody.put("streamType", 0);
        jsonBody.put("protocol", "hls");
        jsonBody.put("transmode", 0);
        jsonBody.put("expand", "transcode=1&videotype=h264");
        String body = jsonBody.toString();
        //参数根据接口实际情况设置
        HttpResponse result = ArtemisHttpUtil.doPostStringImgArtemis(config, path, body, query, null, "application/json", head);
//        System.out.println("海康完成请求");
        try {
            String strResult = EntityUtils.toString(result.getEntity());
//            System.out.println("海康返回结果:" + strResult);
//            HttpResponseResult responseResult = com.alibaba.fastjson.JSONObject.parseObject(strResult, HttpResponseResult.class);
//            if ("0".equals(responseResult.getCode())) {
//                com.alibaba.fastjson.JSONObject jsonObject = responseResult.getData();
//                String url = jsonObject.getString("url");
//                return url;
//            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
}