From 930af27be7e8f071ee26db7cd4b853e150b453dd Mon Sep 17 00:00:00 2001
From: zengh <123456>
Date: Tue, 31 Aug 2021 17:05:40 +0800
Subject: [PATCH] 海康问题修复

---
 blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/hk/util/GetCameraPreviewURL.java |  132 +++++++++++++++++++++++++++++++++++++-------
 blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/hk/constant/HkConstant.java      |    5 +
 2 files changed, 116 insertions(+), 21 deletions(-)

diff --git a/blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/hk/constant/HkConstant.java b/blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/hk/constant/HkConstant.java
index 73e4cce..6af197d 100644
--- a/blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/hk/constant/HkConstant.java
+++ b/blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/hk/constant/HkConstant.java
@@ -39,6 +39,11 @@
 	public static final String previewURLs = "/api/video/v2/cameras/previewURLs";
 
 	/**
+	 * 设备查询
+	 */
+	public static final String camerasID = "/api/irds/v2/resource/resourcesByParams";
+
+	/**
 	 * 语音对讲
 	 */
 	public static final String talkURLs = "/api/video/v1/cameras/talkURLs";
diff --git a/blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/hk/util/GetCameraPreviewURL.java b/blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/hk/util/GetCameraPreviewURL.java
index 3226ea1..0adf351 100644
--- a/blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/hk/util/GetCameraPreviewURL.java
+++ b/blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/hk/util/GetCameraPreviewURL.java
@@ -1,12 +1,17 @@
 package org.springblade.jfpt.hk.util;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.google.gson.JsonArray;
 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.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import static org.springblade.jfpt.hk.constant.HkConstant.ARTEMIS_PATH;
@@ -15,11 +20,12 @@
 
 	/**
 	 * 获取视频预览数据
-	 * @param url 视频预览url
-	 * @param cameraIndexCode  监控点唯一标识
+	 *
+	 * @param url             视频预览url
+	 * @param cameraIndexCode 监控点唯一标识
 	 * @return
 	 */
-	public static String GetCameraPreviewURL(String url,String cameraIndexCode,String protocol) {
+	public static String GetCameraPreviewURL(String url, String cameraIndexCode, String protocol) {
 
 		/**
 		 * STEP1:设置平台参数,根据实际情况,设置host appkey appsecret 三个参数.
@@ -30,7 +36,6 @@
 		ArtemisConfig.appKey = HkConstant.AppKey;
 		// 秘钥appSecret
 		ArtemisConfig.appSecret = HkConstant.AppSecret;
-
 
 
 		/**
@@ -62,19 +67,18 @@
 		/**
 		 * STEP6:调用接口
 		 */
-		String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType , null);// post请求application/json类型参数
+		String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null);// post请求application/json类型参数
 		return result;
 	}
 
-
-
 	/**
-	 * 语音对讲
-	 * @param url 语音对讲url
-	 * @param cameraIndexCode  监控点唯一标识
+	 * 获取视频预览数据
+	 *
+	 * @param url        视频预览url
+	 * @param cameraCode 监控点唯一标识
 	 * @return
 	 */
-	public static String GetTalkURLs(String url,String cameraIndexCode) {
+	public static String QueryCameraPreviewURL(String url, String cameraCode, String resourceType, String key) {
 
 		/**
 		 * STEP1:设置平台参数,根据实际情况,设置host appkey appsecret 三个参数.
@@ -86,6 +90,67 @@
 		// 秘钥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();
+		List<JSONObject> list = new ArrayList<>();
+		List list2 = new ArrayList();
+		JSONObject map = new JSONObject();
+		list2.add(cameraCode);
+		map.put("key", key);
+		map.put("operator", 0);
+		map.put("values", list2);
+		list.add(map);
+		jsonBody.put("pageNo", 1);
+		jsonBody.put("pageSize", 100);
+		jsonBody.put("resourceType", resourceType);
+		jsonBody.put("expressions", list);
+		String body = jsonBody.toJSONString();
+		System.out.println(jsonBody);
+		/**
+		 * STEP6:调用接口
+		 */
+		String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null);// post请求application/json类型参数
+		return result;
+	}
+
+
+	/**
+	 * 语音对讲
+	 *
+	 * @param url             语音对讲url
+	 * @param cameraIndexCode 监控点唯一标识
+	 * @return
+	 */
+	public static String GetTalkURLs(String url, String cameraIndexCode) {
+
+		/**
+		 * STEP1:设置平台参数,根据实际情况,设置host appkey appsecret 三个参数.
+		 */
+		// artemis网关服务器ip端口
+		ArtemisConfig.host = HkConstant.HOST;
+		// 秘钥appKey
+		ArtemisConfig.appKey = HkConstant.AppKey;
+		// 秘钥appSecret
+		ArtemisConfig.appSecret = HkConstant.AppSecret;
 
 
 		/**
@@ -109,25 +174,26 @@
 		 */
 		JSONObject jsonBody = new JSONObject();
 		jsonBody.put("cameraIndexCode", cameraIndexCode);
-		jsonBody.put("streamType", 0);
-		jsonBody.put("transmode", 1);
-		jsonBody.put("expand", "streamform=ps");
-		jsonBody.put("protocol", "ws");
+//		jsonBody.put("streamType", 0);
+//		jsonBody.put("transmode", 1);
+//		jsonBody.put("expand", "streamform=ps");
+//		jsonBody.put("protocol", "ws");
 		String body = jsonBody.toJSONString();
 		/**
 		 * STEP6:调用接口
 		 */
-		String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType , null);// post请求application/json类型参数
+		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) {
+	public static String GetCameraResourcePage(Integer pageNo, Integer pageSize, String url) {
 
 		/**
 		 * STEP1:设置平台参数,根据实际情况,设置host appkey appsecret 三个参数.
@@ -167,16 +233,40 @@
 		 * STEP6:调用接口并返回数据
 		 * post请求application/json类型参数;
 		 */
-		return ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType , null);
+		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);
-		String result2 = GetTalkURLs(HkConstant.previewURLs,"1f792961883543c6868cc8b200291962");
+		String result = GetCameraResourcePage(1, 1, HkConstant.cameras);
+		//根据设备id获取设备编号
+		String result1 = QueryCameraPreviewURL(HkConstant.camerasID, "111111", "encodeDevice", "deviceCode");
+
+		JSONObject jsonObject1 = JSONObject.parseObject(result1);
+		JSONObject res1 = (JSONObject) jsonObject1.get("data");
+		JSONArray arr1 = JSON.parseArray(res1.getString("list"));
+		JSONObject data1 = (JSONObject) arr1.get(0);
+		String code1 = data1.get("indexCode").toString();
+
+		//根据设备编号获取子节点编号
+		String result2 = QueryCameraPreviewURL(HkConstant.camerasID, code1, "camera", "parentIndexCode");
+
+		JSONObject jsonObject2 = JSONObject.parseObject(result2);
+		JSONObject res2 = (JSONObject) jsonObject2.get("data");
+		JSONArray arr2 = JSON.parseArray(res2.getString("list"));
+		JSONObject data2 = (JSONObject) arr2.get(0);
+		String code2 = data2.get("indexCode").toString();
+
+		//根据子节点编号获取设备播放地址
+		String result3 = GetCameraPreviewURL(HkConstant.previewURLs, code2, ProtocolConstant.HLS);
+		//根据子节点编号获取音频对讲地址
+		String result4 = GetTalkURLs(HkConstant.previewURLs, code2);
+
+
 		System.out.println("result结果示例: " + result);
 		System.out.println("result1 = " + result1);
 		System.out.println("result2 = " + result2);
+		System.out.println("result3 = " + result3);
+		System.out.println("result4 = " + result4);
 	}
 }

--
Gitblit v1.9.3