Ver código fonte

获取海康获取监控点预览取流URLv2 分页获取监控点资源

bihuisong 4 meses atrás
pai
commit
ffcc7b9a24

+ 6 - 1
qmjszx-admin/src/main/resources/application.yml

@@ -146,7 +146,7 @@ rsa:
   publicKey: MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAIdmTeQdUyYK2a5ivPXdYArOgDMDKu6ob7YPlaC6R1/XxjHhGaSIucYGrzO+JhCFNkhgHxmc4POpyFq+PFdLuNMCAwEAAQ==
   # 私钥
   privateKey: MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAh2ZN5B1TJgrZrmK89d1gCs6AMwMq7qhvtg+VoLpHX9fGMeEZpIi5xgavM74mEIU2SGAfGZzg86nIWr48V0u40wIDAQABAkBbgNXu7ap9sSN/aJcPCXaYlwmob+GZvBcS0OFr57fImsxTEzWg/OJWxcbHk7Li31AbHjwqQmVtUxk2wQ6GawthAiEAve5+CCaUHV3BIH7LhzU7MsPAr6IIx25t1NkNNg+dn3kCIQC2f7XtdTOVRtPUwO7QhwC0fX/wJu53pR01p55tqmgLqwIgYzUHr8o243/tOMQCG4W6fjGxnAvO+hy8UcluFSbi9kECIQCAK4NOyPA4V6zwD6vpgdcJ69YNiJoUJz8zboxCwtodzwIgNUN6uuiVJuZmBJDm+9AIY7Ury+ajGRZJ7l1FIBbxMPY=
-# 微信支付配置
+
 # 微信支付配置 notifyUrl:微信支付异步回调地址
 wx:
   pay:
@@ -158,6 +158,11 @@ wx:
     privateKeyPath: #证书认证是生成文件
     merchantserialNumber: #证书序列号
 
+# 海康获取直播视频流配置
+hik:
+  appKey: "28356728"
+  appSecret: "C3K889wQUgVlSj1BMay6"
+  host: "218.62.80.146:1443"
 
 
 

+ 7 - 0
qmjszx-business/pom.xml

@@ -80,6 +80,13 @@
             <version>2.5.0</version>
         </dependency>
 
+        <!--海康-->
+        <dependency>
+            <groupId>com.hikvision.ga</groupId>
+            <artifactId>artemis-http-client</artifactId>
+            <version>1.1.3</version>
+        </dependency>
+
     </dependencies>
 
 </project>

+ 39 - 7
qmjszx-business/src/main/java/beilv/hk/controller/HKController.java

@@ -1,16 +1,48 @@
 package beilv.hk.controller;
 
-import java.util.HashMap;
+import beilv.common.core.domain.AjaxResult;
+import beilv.hk.controller.utils.GetCameraPreviewURL;
+import beilv.hk.controller.utils.GetCameras;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.util.CollectionUtils;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Map;
 
-public class HKController {
-
-
-
-
-
 
+@RestController
+@RequestMapping("/app-api/hik")
+public class HKController {
 
+    @Value("${hik.appKey}")
+    private String appKey;
+    @Value("${hik.appSecret}")
+    private String appSecret;
+    @Value("${hik.host}")
+    private String host;
+
+
+    /**
+     * 根据userId查询用户积分流水列表
+     */
+    @GetMapping("/getCameraPreviewURL")
+    @ResponseBody
+    public AjaxResult getCameraPreviewURL() {
+        List<String> urlList = new ArrayList<>();
+        List<Map<String, Object>> cameras = GetCameras.getCameras(host, appKey, appSecret);
+        if (!CollectionUtils.isEmpty(cameras)) {
+            for (Map<String, Object> map : cameras) {
+                String url = GetCameraPreviewURL.getCameraPreviewURL(host, appKey, appSecret, map.get("cameraIndexCode").toString());
+                urlList.add(url);
+            }
+        }
+        return AjaxResult.success(urlList);
+    }
 
 
 }

+ 46 - 0
qmjszx-business/src/main/java/beilv/hk/controller/utils/GetCameraPreviewURL.java

@@ -0,0 +1,46 @@
+package beilv.hk.controller.utils;
+
+import com.alibaba.fastjson.JSONObject;
+import com.hikvision.artemis.sdk.ArtemisHttpUtil;
+import com.hikvision.artemis.sdk.config.ArtemisConfig;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 获取监控点预览取流URLv2
+ */
+public class GetCameraPreviewURL {
+
+    public static String getCameraPreviewURL(String host, String appKey, String appSecret, String cameraIndexCode) {
+        String url = null;
+        ArtemisConfig.host = host; // 平台的ip端口
+        ArtemisConfig.appKey = appKey;  // 密钥appkey
+        ArtemisConfig.appSecret = appSecret;// 密钥appSecret
+        final String ARTEMIS_PATH = "/artemis";
+        final String previewURLsApi = ARTEMIS_PATH + "/api/video/v1/cameras/previewURLs";
+        Map<String, String> path = new HashMap<String, String>(2) {
+            {
+                put("https://", previewURLsApi);//根据现场环境部署确认是http还是https
+            }
+        };
+        String contentType = "application/json";
+        JSONObject jsonBody = new JSONObject();
+        jsonBody.put("cameraIndexCode", cameraIndexCode);
+        jsonBody.put("streamType", 0);
+        jsonBody.put("protocol", "ws");
+        jsonBody.put("transmode", 1);
+        jsonBody.put("expand", "streamform=ps");
+        String body = jsonBody.toJSONString();
+        JSONObject json = JSONObject.parseObject(ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null));// post请求application/json类型参数
+        if (json.get("code").equals("0")) {
+            url = JSONObject.parseObject(json.get("data").toString()).get("url").toString();
+        }
+        return url;
+    }
+
+    public static void main(String[] args) {
+        String result = getCameraPreviewURL("218.62.80.146:1443", "28356728", "C3K889wQUgVlSj1BMay6", "fd98e88146904ceba1e30081e61b47f9");
+        System.out.println("result结果示例: " + result);
+    }
+}

+ 60 - 0
qmjszx-business/src/main/java/beilv/hk/controller/utils/GetCameras.java

@@ -0,0 +1,60 @@
+package beilv.hk.controller.utils;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.hikvision.artemis.sdk.ArtemisHttpUtil;
+import com.hikvision.artemis.sdk.config.ArtemisConfig;
+import lombok.extern.slf4j.Slf4j;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 分页获取监控点资源
+ */
+@Slf4j
+public class GetCameras {
+
+    public static List<Map<String, Object>> getCameras(String host, String appKey, String appSecret) {
+        List<Map<String, Object>> list = new ArrayList<>();
+
+        ArtemisConfig.host = host; // 平台的ip端口
+        ArtemisConfig.appKey = appKey;  // 密钥appkey
+        ArtemisConfig.appSecret = appSecret;// 密钥appSecret
+
+        final String ARTEMIS_PATH = "/artemis";
+        final String previewURLsApi = ARTEMIS_PATH + "/api/resource/v1/cameras";
+        Map<String, String> path = new HashMap<String, String>(2) {
+            {
+                put("https://", previewURLsApi);//根据现场环境部署确认是http还是https
+            }
+        };
+        String contentType = "application/json";
+        JSONObject jsonBody = new JSONObject();
+        jsonBody.put("pageNo", 1);
+        jsonBody.put("pageSize", 2);
+        String body = jsonBody.toJSONString();
+        JSONObject json = JSONObject.parseObject(ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null));// post请求application/json类型参数
+        if (json.get("code").equals("0")) {
+            JSONArray jsonArray = JSONObject.parseArray(JSONObject.parseObject(json.get("data").toString()).get("list").toString());
+            ObjectMapper objectMapper = new ObjectMapper();
+            try {
+                list = objectMapper.readValue(jsonArray.toString(), new TypeReference<List<Map<String, Object>>>() {
+                });
+            } catch (JsonProcessingException e) {
+                throw new RuntimeException(e);
+            }
+        }
+        return list;
+    }
+
+    public static void main(String[] args) {
+        List<Map<String, Object>> result = getCameras("218.62.80.146:1443", "28356728", "C3K889wQUgVlSj1BMay6");
+        System.out.println("result结果示例: " + result);
+    }
+}