Browse Source

# 视频流转换为ws测试接口

zhongwei
haungxing 11 months ago
parent
commit
b111a1ee73
  1. 4
      hzims-biz-common/pom.xml
  2. 72
      hzims-biz-common/src/main/java/com/hnac/hzims/common/utils/HiKUtil.java
  3. 10
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/controller/StationVideoTypeController.java
  4. 7
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationVideoTypeService.java
  5. 48
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationVideoTypeServiceImpl.java

4
hzims-biz-common/pom.xml

@ -44,6 +44,10 @@
<groupId>org.springblade</groupId> <groupId>org.springblade</groupId>
<artifactId>blade-starter-datascope</artifactId> <artifactId>blade-starter-datascope</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.hikvision.ga</groupId>
<artifactId>artemis-http-client</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>

72
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<String, Object> map) {
ArtemisConfig.host = HOST;
ArtemisConfig.appKey = APP_KEY;
ArtemisConfig.appSecret = APP_SECRET;
final String url = "/artemis" + api;
Map<String, String> path = new HashMap<String,String>(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<String, Object> map, String host,String appKey,String appSecret) {
ArtemisConfig.host = host;
ArtemisConfig.appKey = appKey;
ArtemisConfig.appSecret = appSecret;
final String url = "/artemis" + api;
Map<String, String> path = new HashMap<String,String>(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");
}
}

10
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("视频监控处理成功"); return R.success("视频监控处理成功");
} }
@GetMapping("/getWsUrlByPointCode")
@ApiOperationSupport(order = 140)
@ApiOperation(value = "根据摄像头设备编码获取ws地址", notes = "根据摄像头设备编码获取ws地址")
public R<Map<String,Object>> 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));
}
} }

7
hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationVideoTypeService.java

@ -69,4 +69,11 @@ public interface IStationVideoTypeService extends BaseService<StationVideoTypeEn
*/ */
Map<HikDeviceResp, List<HikMonitorResp>> getMonitorsByStation(String stationId); Map<HikDeviceResp, List<HikMonitorResp>> getMonitorsByStation(String stationId);
/**
* 根据摄像头设备编码获取ws地址
* @param pointCodes 摄像头设备编码
* @return ws地址
*/
Map<String,Object> getWsUrlByPointCode(String pointCodes,String host,String appKey,String appSecret);
} }

48
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.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; 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.config.HikPathConfiguration;
import com.hnac.hzims.operational.station.StationConstants; import com.hnac.hzims.operational.station.StationConstants;
import com.hnac.hzims.operational.station.dto.StationVideoTypeDTO; import com.hnac.hzims.operational.station.dto.StationVideoTypeDTO;
@ -35,10 +36,7 @@ import org.springframework.stereotype.Service;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList; import java.util.*;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -56,6 +54,16 @@ public class StationVideoTypeServiceImpl extends BaseServiceImpl<StationVideoTyp
private String videoLoginUrl; private String videoLoginUrl;
@Value("${hzims.video.random-code}") @Value("${hzims.video.random-code}")
private String definitionCode; private String definitionCode;
/** 秘钥appKey **/
@Value("${hzims.videoProperties.appKey}")
private String videoAppKey;
/** 代理API网关nginx服务器ip端口 **/
@Value("${hzims.videoProperties.videoHost}")
private String videoHost;
/** 秘钥appSecret **/
@Value("${hzims.videoProperties.appSecret}")
private String videoAppSecret;
/** /**
* 获取海康视频接口 * 获取海康视频接口
* @return * @return
@ -190,6 +198,38 @@ public class StationVideoTypeServiceImpl extends BaseServiceImpl<StationVideoTyp
} }
@Override @Override
public Map<String, Object> getWsUrlByPointCode(String pointCodes,String host,String appKey,String appSecret) {
Map<String,Object> 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<String,Object> param = new HashMap<String,Object>(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<String, String> url = new HashMap<String, String>() {{
put("url",data);
}};
result.put(pointCode,url);
}
}
catch (Exception e) {
e.printStackTrace();
}
});
return result;
}
@Override
public StationVideoTypeEntity getById(Long id,int streamType){ public StationVideoTypeEntity getById(Long id,int streamType){
StationVideoTypeEntity stationVideoTypeEntity = this.getById(id); StationVideoTypeEntity stationVideoTypeEntity = this.getById(id);
if(ObjectUtil.isNotEmpty(stationVideoTypeEntity.getIsHikvideo()) && stationVideoTypeEntity.getIsHikvideo() == 1){ if(ObjectUtil.isNotEmpty(stationVideoTypeEntity.getIsHikvideo()) && stationVideoTypeEntity.getIsHikvideo() == 1){

Loading…
Cancel
Save