南昌市物联网技防平台-后台
Administrator
2021-08-09 639f6875c66d9099bdb312ce15e47e1f79d638b6
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package org.springblade.jfpt.hk.util;
 
import com.alibaba.fastjson.JSONObject;
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
import com.hikvision.artemis.sdk.config.ArtemisConfig;
import org.springblade.jfpt.hk.constant.HkConstant;
import org.springblade.jfpt.hk.constant.ProtocolConstant;
 
import java.util.HashMap;
import java.util.Map;
 
import static org.springblade.jfpt.hk.constant.HkConstant.ARTEMIS_PATH;
 
public class GetCameraPreviewURL {
 
    /**
     * 获取视频预览数据
     * @param url 视频预览url
     * @param cameraIndexCode  监控点唯一标识
     * @return
     */
    public static String GetCameraPreviewURL(String url,String cameraIndexCode,String protocol) {
 
        /**
         * STEP1:设置平台参数,根据实际情况,设置host appkey appsecret 三个参数.
         */
        // artemis网关服务器ip端口
        ArtemisConfig.host = HkConstant.HOST;
        // 秘钥appKey
        ArtemisConfig.appKey = HkConstant.AppKey;
        // 秘钥appSecret
        ArtemisConfig.appSecret = HkConstant.AppSecret;
 
 
 
        /**
         * STEP3:设置接口的URI地址
         */
        final String apiUrl = ARTEMIS_PATH + url;
        Map<String, String> path = new HashMap<String, String>(2) {
            {
                //根据现场环境部署确认是http还是https
                put("https://", apiUrl);
            }
        };
 
        /**
         * STEP4:设置参数提交方式
         */
        String contentType = "application/json";
 
        /**
         * STEP5:组装请求参数
         */
        JSONObject jsonBody = new JSONObject();
        jsonBody.put("cameraIndexCode", cameraIndexCode);
        jsonBody.put("streamType", 0);
        jsonBody.put("protocol", protocol);
        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类型参数
        return result;
    }
 
 
    /**
     * 获取监控点资源分页数据
     * @param url 监控资源url
     * @return
     */
    public static String GetCameraResourcePage(Integer pageNo,Integer pageSize,String url) {
 
        /**
         * STEP1:设置平台参数,根据实际情况,设置host appkey appsecret 三个参数.
         */
        // artemis网关服务器ip端口
        ArtemisConfig.host = HkConstant.HOST;
        // 秘钥appKey
        ArtemisConfig.appKey = HkConstant.AppKey;
        // 秘钥appSecret
        ArtemisConfig.appSecret = HkConstant.AppSecret;
 
 
 
        /**
         * STEP3:设置接口的URI地址
         */
        final String apiUrl = ARTEMIS_PATH + url;
        Map<String, String> path = new HashMap<String, String>(2) {
            {
                //根据现场环境部署确认是http还是https
                put("https://", apiUrl);
            }
        };
 
        /**
         * STEP4:设置参数提交方式
         */
        String contentType = "application/json";
 
        /**
         * STEP5:组装请求参数
         */
        JSONObject jsonBody = new JSONObject();
        jsonBody.put("pageNo", pageNo);
        jsonBody.put("pageSize", pageSize);
        String body = jsonBody.toJSONString();
 
        /**
         * STEP6:调用接口并返回数据
         * post请求application/json类型参数;
         */
        return ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType , null);
    }
 
    public static void main(String[] args) {
 
        String result = GetCameraResourcePage(1,1,HkConstant.cameras);
        String result1 = GetCameraPreviewURL(HkConstant.previewURLs,"1f792961883543c6868cc8b200291962", ProtocolConstant.HLS);
        System.out.println("result结果示例: " + result);
        System.out.println("result1 = " + result1);
    }
}