|
@@ -0,0 +1,191 @@
|
|
|
+package com.usky.hik.controller.api;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.hikvision.artemis.sdk.ArtemisHttpUtil;
|
|
|
+import com.hikvision.artemis.sdk.Client;
|
|
|
+import com.hikvision.artemis.sdk.Request;
|
|
|
+import com.hikvision.artemis.sdk.Response;
|
|
|
+import com.hikvision.artemis.sdk.config.ArtemisConfig;
|
|
|
+import com.hikvision.artemis.sdk.constant.Constants;
|
|
|
+import com.hikvision.artemis.sdk.enums.Method;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 海康视频api
|
|
|
+ * @author han
|
|
|
+ * @date 2023/10/29 13:21
|
|
|
+ */
|
|
|
+
|
|
|
+public class HkVideoApi {
|
|
|
+ private static final Logger logger = LoggerFactory.getLogger(ArtemisHttpUtil.class);
|
|
|
+
|
|
|
+ static {
|
|
|
+ /**
|
|
|
+ * 添加连接配置
|
|
|
+ */
|
|
|
+ ArtemisConfig.host = "192.168.10.101:443";
|
|
|
+ /**
|
|
|
+ * 密钥appkey
|
|
|
+ */
|
|
|
+ ArtemisConfig.appKey = "27427790";
|
|
|
+ /**
|
|
|
+ * 密钥appSecret
|
|
|
+ */
|
|
|
+ ArtemisConfig.appSecret = "lqIzdXZElwxNYS0a1YqZ";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 实时视频
|
|
|
+ * @param cameraIndexCode
|
|
|
+ * @param streamType
|
|
|
+ * @param protocol
|
|
|
+ * @param transmode
|
|
|
+ * @param expand
|
|
|
+ * @param streamform
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static String getVideoUrl(String cameraIndexCode, Integer streamType,String protocol,Integer transmode,String expand,
|
|
|
+ String streamform){
|
|
|
+ /**
|
|
|
+ * 获取视频资源
|
|
|
+ */
|
|
|
+ /**
|
|
|
+ * STEP2:设置OpenAPI接口的上下文
|
|
|
+ */
|
|
|
+ final String ARTEMIS_PATH = "/artemis";
|
|
|
+ final String url = ARTEMIS_PATH+"/api/video/v1/cameras/previewURLs";
|
|
|
+ Map<String, String> path = new HashMap<String, String>(2) {
|
|
|
+ {
|
|
|
+ put("https://", url);//根据现场环境部署确认是http还是https
|
|
|
+ }
|
|
|
+ };
|
|
|
+ /**
|
|
|
+ * 添加请求参数
|
|
|
+ */
|
|
|
+ JSONObject jsonBody = new JSONObject();
|
|
|
+ if (StringUtils.isNotBlank(cameraIndexCode)){
|
|
|
+ jsonBody.put("cameraIndexCode", cameraIndexCode);
|
|
|
+ }
|
|
|
+ if (null != streamType){
|
|
|
+ jsonBody.put("streamType", streamType);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(protocol)){
|
|
|
+ jsonBody.put("protocol", protocol);
|
|
|
+ }
|
|
|
+ if (null != transmode){
|
|
|
+ jsonBody.put("transmode", transmode);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(expand)){
|
|
|
+ jsonBody.put("expand", expand);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(streamform)){
|
|
|
+ jsonBody.put("streamform", streamform);
|
|
|
+ }
|
|
|
+ String body = jsonBody.toJSONString();
|
|
|
+ /**
|
|
|
+ * STEP4:设置参数提交方式
|
|
|
+ */
|
|
|
+ String contentType = "application/json";
|
|
|
+ return ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType , null);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 使用签名请求海康数据服务接口
|
|
|
+ * @param path
|
|
|
+ * @param body
|
|
|
+ * @param signature
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static String doPostSignatureStringArtemis(Map<String, String> path, String body, String signature) {
|
|
|
+ String httpSchema = (String)path.keySet().toArray()[0];
|
|
|
+ if (httpSchema != null && !StringUtils.isEmpty(httpSchema)) {
|
|
|
+ String responseStr = null;
|
|
|
+
|
|
|
+ try {
|
|
|
+ Map<String, String> headers = new HashMap();
|
|
|
+ headers.put("Accept", "*/*");
|
|
|
+ headers.put("Content-Type", "application/text;charset=UTF-8");
|
|
|
+ headers.put("x-ca-key","27427790");
|
|
|
+ headers.put("x-ca-signature-headers","x-ca-key");
|
|
|
+ headers.put("x-ca-signature",signature);
|
|
|
+
|
|
|
+ Request request = new Request(Method.POST_STRING, httpSchema + ArtemisConfig.host, (String)path.get(httpSchema), ArtemisConfig.appKey, ArtemisConfig.appSecret, Constants.DEFAULT_TIMEOUT);
|
|
|
+ request.setHeaders(headers);
|
|
|
+ request.setStringBody(body);
|
|
|
+ Response response = Client.execute(request);
|
|
|
+ responseStr = getResponseResult(response);
|
|
|
+ } catch (Exception var11) {
|
|
|
+ logger.error("the Artemis PostString Request is failed[doPostStringArtemis]", var11);
|
|
|
+ }
|
|
|
+
|
|
|
+ return responseStr;
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("http和https参数错误httpSchema: " + httpSchema);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String getResponseResult(Response response) {
|
|
|
+ String responseStr = null;
|
|
|
+ int statusCode = response.getStatusCode();
|
|
|
+ if (!String.valueOf(statusCode).startsWith("2") && !String.valueOf(statusCode).startsWith("3")) {
|
|
|
+ String msg = response.getErrorMessage();
|
|
|
+ responseStr = response.getBody();
|
|
|
+ logger.error("the Artemis Request is Failed,statusCode:" + statusCode + " errorMsg:" + msg);
|
|
|
+ } else {
|
|
|
+ responseStr = response.getBody();
|
|
|
+ logger.info("the Artemis Request is Success,statusCode:" + statusCode + " SuccessMsg:" + response.getBody());
|
|
|
+ }
|
|
|
+
|
|
|
+ return responseStr;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 行车记录
|
|
|
+ * @param startTime
|
|
|
+ * @param endTime
|
|
|
+ * @param pageNo
|
|
|
+ * @param pageSize
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static String driverRecord(String startTime, String endTime,Integer pageNo,Integer pageSize){
|
|
|
+
|
|
|
+ /**
|
|
|
+ * STEP2:设置OpenAPI接口的上下文
|
|
|
+ */
|
|
|
+ final String ARTEMIS_PATH = "/artemis";
|
|
|
+ final String url = ARTEMIS_PATH+"/api/pms/v1/crossRecords/page";
|
|
|
+ Map<String, String> path = new HashMap<String, String>(2) {
|
|
|
+ {
|
|
|
+ put("https://", url);//根据现场环境部署确认是http还是https
|
|
|
+ }
|
|
|
+ };
|
|
|
+ /**
|
|
|
+ * 添加请求参数
|
|
|
+ */
|
|
|
+ JSONObject jsonBody = new JSONObject();
|
|
|
+ if (StringUtils.isNotBlank(startTime)){
|
|
|
+ jsonBody.put("startTime", startTime);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(endTime)){
|
|
|
+ jsonBody.put("endTime", endTime);
|
|
|
+ }
|
|
|
+ if (null != pageNo){
|
|
|
+ jsonBody.put("pageNo", pageNo);
|
|
|
+ }
|
|
|
+ if (null != pageSize){
|
|
|
+ jsonBody.put("pageSize", pageSize);
|
|
|
+ }
|
|
|
+ String body = jsonBody.toJSONString();
|
|
|
+ /**
|
|
|
+ * STEP4:设置参数提交方式
|
|
|
+ */
|
|
|
+ String contentType = "application/json";
|
|
|
+
|
|
|
+ return ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType , null);
|
|
|
+ }
|
|
|
+}
|