czt
2025-06-10 694f541f9f4bc51818395be84e5ddf322c8048d8
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
package com.ld.igds.protocol.hikmedia;
 
 
import com.alibaba.fastjson.JSONObject;
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
import com.hikvision.artemis.sdk.config.ArtemisConfig;
import com.ld.igds.protocol.hikmedia.data.ApiHikParam;
import com.ld.igds.protocol.hikmedia.data.CameraPlay;
import com.ld.igds.protocol.hikmedia.data.HikRespData;
 
import java.util.HashMap;
import java.util.Map;
 
/**
 * 海康视频流媒体API调用管理-预览相关
 */
public class ApiCameraPreview {
 
    private final static ApiCameraPreview instance = new ApiCameraPreview();
 
    private ApiCameraPreview() {
    }
 
    public static ApiCameraPreview getInstance() {
        return instance;
    }
 
 
    /**
     * 获取监控点预览取流URLv2
     *
     * @param param
     * @return
     */
    public HikRespData<CameraPlay> apiPreview(ApiHikParam param) {
 
        /**
         * STEP1:设置平台参数,根据实际情况,设置host appkey appsecret 三个参数.
         */
        ArtemisConfig.host = param.getWanIp() + ":" + param.getPort(); // 平台的ip端口
        ArtemisConfig.appKey = param.getAppKey();  // 密钥appkey
        ArtemisConfig.appSecret = param.getAppSecret();// 密钥appSecret
 
        /**
         * STEP2:设置OpenAPI接口的上下文
         */
        final String ARTEMIS_PATH = param.getArtemisPath();
 
        /**
         * STEP3:设置接口的URI地址
         */
        final String urlAPi = ARTEMIS_PATH + "/api/video/v2/cameras/previewURLs";
 
 
        Map<String, String> path = new HashMap<String, String>(2) {
            {
                put("http://", urlAPi);//根据现场环境部署确认是http还是https
            }
        };
 
        /**
         * STEP4:设置参数提交方式
         */
        String contentType = "application/json";
 
        /**
         * STEP5:组装请求参数
         */
        JSONObject jsonBody = new JSONObject();
        jsonBody.put("cameraIndexCode", param.getDeviceCode());
        jsonBody.put("streamType", 0);
        jsonBody.put("protocol", "hls");
        jsonBody.put("transmode", 1);
        jsonBody.put("expand", "transcode=0");
        jsonBody.put("streamform", "rtp");
        String body = jsonBody.toJSONString();
 
        /**
         * STEP6:调用接口
         */
        String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null);// post请求application/json类型参数
 
 
        HikRespData<CameraPlay> data = JSONObject.parseObject(result, HikRespData.class);
 
 
        return data;
    }
 
 
}