From b111a1ee7360a423ecce9c31f2900f2d4b10f482 Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Thu, 11 Jan 2024 08:54:09 +0800 Subject: [PATCH] =?UTF-8?q?#=20=E8=A7=86=E9=A2=91=E6=B5=81=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2=E4=B8=BAws=E6=B5=8B=E8=AF=95=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hzims-biz-common/pom.xml | 4 ++ .../java/com/hnac/hzims/common/utils/HiKUtil.java | 72 ++++++++++++++++++++++ .../controller/StationVideoTypeController.java | 10 +++ .../station/service/IStationVideoTypeService.java | 7 +++ .../service/impl/StationVideoTypeServiceImpl.java | 48 +++++++++++++-- 5 files changed, 137 insertions(+), 4 deletions(-) create mode 100644 hzims-biz-common/src/main/java/com/hnac/hzims/common/utils/HiKUtil.java diff --git a/hzims-biz-common/pom.xml b/hzims-biz-common/pom.xml index f1d1274..4908ce6 100644 --- a/hzims-biz-common/pom.xml +++ b/hzims-biz-common/pom.xml @@ -44,6 +44,10 @@ org.springblade blade-starter-datascope + + com.hikvision.ga + artemis-http-client + diff --git a/hzims-biz-common/src/main/java/com/hnac/hzims/common/utils/HiKUtil.java b/hzims-biz-common/src/main/java/com/hnac/hzims/common/utils/HiKUtil.java new file mode 100644 index 0000000..7481619 --- /dev/null +++ b/hzims-biz-common/src/main/java/com/hnac/hzims/common/utils/HiKUtil.java @@ -0,0 +1,72 @@ +package com.hnac.hzims.common.utils; + +import com.alibaba.druid.support.json.JSONUtils; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.fasterxml.jackson.databind.JsonNode; +import com.hikvision.artemis.sdk.ArtemisHttpUtil; +import com.hikvision.artemis.sdk.config.ArtemisConfig; +import okhttp3.MediaType; +import okhttp3.MultipartBody; +import okhttp3.RequestBody; +import org.springblade.core.log.exception.ServiceException; +import org.springblade.core.log.logger.BladeLogger; +import org.springblade.core.tool.jackson.JsonUtil; +import org.springblade.core.tool.utils.DateUtil; +import org.springblade.core.tool.utils.Func; +import org.springblade.server.domain.Sys; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.util.Assert; + +import java.text.DateFormat; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.ZoneOffset; +import java.time.format.DateTimeFormatter; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + +/** + * @Author: huangxing + * @Date: 2024/1/10 14:40 + */ +public class HiKUtil { + + public static String APP_KEY = "26486442"; + public static String APP_SECRET = "tXBM9jsMqeM9yvEMS8qg"; + public static String HOST = "140.210.208.111:443"; + + public static String send(String api, Map map) { + ArtemisConfig.host = HOST; + ArtemisConfig.appKey = APP_KEY; + ArtemisConfig.appSecret = APP_SECRET; + + final String url = "/artemis" + api; + Map path = new HashMap(2){{ + put("https://", url); + }}; + String contentType = "application/json"; + String body = JSON.toJSONString(map); + String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null); + JSONObject object = JsonUtil.parse(result, JSONObject.class); + return object.getString("data"); + } + + public static String send(String api, Map map, String host,String appKey,String appSecret) { + ArtemisConfig.host = host; + ArtemisConfig.appKey = appKey; + ArtemisConfig.appSecret = appSecret; + + final String url = "/artemis" + api; + Map path = new HashMap(2){{ + put("https://", url); + }}; + String contentType = "application/json"; + String body = JSON.toJSONString(map); + String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null); + JSONObject object = JsonUtil.parse(result, JSONObject.class); + return object.getString("data"); + } + +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/controller/StationVideoTypeController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/controller/StationVideoTypeController.java index 4c47925..e1cac85 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/controller/StationVideoTypeController.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/controller/StationVideoTypeController.java @@ -301,4 +301,14 @@ public class StationVideoTypeController extends BladeController { return R.success("视频监控处理成功"); } + @GetMapping("/getWsUrlByPointCode") + @ApiOperationSupport(order = 140) + @ApiOperation(value = "根据摄像头设备编码获取ws地址", notes = "根据摄像头设备编码获取ws地址") + public R> getWsUrlByPointCode(@RequestParam(value = "pointCodes",required = false) String pointCodes, + @RequestParam(value = "host",required = false) String host, + @RequestParam(value = "appKey",required = false) String appKey, + @RequestParam(value = "appSecret",required = false) String appSecret) { + return R.data(stationVideoTypeService.getWsUrlByPointCode(pointCodes,host,appKey,appSecret)); + } + } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationVideoTypeService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationVideoTypeService.java index 3a57ea4..01d55b1 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationVideoTypeService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationVideoTypeService.java @@ -69,4 +69,11 @@ public interface IStationVideoTypeService extends BaseService> getMonitorsByStation(String stationId); + /** + * 根据摄像头设备编码获取ws地址 + * @param pointCodes 摄像头设备编码 + * @return ws地址 + */ + Map getWsUrlByPointCode(String pointCodes,String host,String appKey,String appSecret); + } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationVideoTypeServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationVideoTypeServiceImpl.java index fd50c95..b4ffcce 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationVideoTypeServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationVideoTypeServiceImpl.java @@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.hnac.hzims.common.utils.HiKUtil; import com.hnac.hzims.operational.config.HikPathConfiguration; import com.hnac.hzims.operational.station.StationConstants; import com.hnac.hzims.operational.station.dto.StationVideoTypeDTO; @@ -35,10 +36,7 @@ import org.springframework.stereotype.Service; import org.springframework.util.Assert; import javax.servlet.http.HttpServletResponse; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; /** @@ -56,6 +54,16 @@ public class StationVideoTypeServiceImpl extends BaseServiceImpl getWsUrlByPointCode(String pointCodes,String host,String appKey,String appSecret) { + Map result = new HashMap<>(); + pointCodes = StringUtil.isNotBlank(pointCodes) ? pointCodes : "7eaf556c7d3e429d89cd622256898776,43ee17dafde94c4ba40ad313ebefe6d2,98f51c998acf4dd2951e0484d265710e,6bb1f8ad552444309b68677b8ac3fbaf"; + final String finalHost = StringUtil.isNotBlank(host) ? host : videoHost; + final String finalAppKey = StringUtil.isNotBlank(appKey) ? appKey : videoAppKey; + final String finalAppSecret = StringUtil.isNotBlank(appSecret) ? appSecret : videoAppSecret; + Map param = new HashMap(6){{ + put("streamType",0); + put("protocol","ws"); + put("transmode",1); + put("expand","transcode=0"); + put("streamform","ps"); + }}; + Arrays.stream(pointCodes.split(",")).forEach(pointCode -> { + param.put("cameraIndexCode",pointCode); + try{ + String data = HiKUtil.send("/api/video/v2/cameras/previewURLs", param, finalHost, finalAppKey, finalAppSecret); + if(StringUtil.isNotBlank(data)) { + Map url = new HashMap() {{ + put("url",data); + }}; + result.put(pointCode,url); + } + } + catch (Exception e) { + e.printStackTrace(); + } + }); + return result; + } + + @Override public StationVideoTypeEntity getById(Long id,int streamType){ StationVideoTypeEntity stationVideoTypeEntity = this.getById(id); if(ObjectUtil.isNotEmpty(stationVideoTypeEntity.getIsHikvideo()) && stationVideoTypeEntity.getIsHikvideo() == 1){