Commit 4ed87df2 authored by 耿迪迪's avatar 耿迪迪

多平台视频播放修改

parent a793e91c
......@@ -61,13 +61,6 @@
<artifactId>huaxin-generator</artifactId>
</dependency>
<!--海康-->
<dependency>
<groupId>com.hikvision.ga</groupId>
<artifactId>artemis-http-client</artifactId>
<version>1.1.3</version>
</dependency>
</dependencies>
<build>
......
......@@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSONObject;
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
import com.hikvision.artemis.sdk.config.ArtemisConfig;
import com.zehong.common.core.domain.AjaxResult;
import com.zehong.common.exception.CustomException;
import com.zehong.common.utils.StringUtils;
import com.zehong.system.domain.vo.EventSubscriptionVo;
import com.zehong.system.domain.vo.EventUnSubscriptionVo;
import org.springframework.web.bind.annotation.*;
......@@ -23,14 +25,14 @@ public class ArtemisController {
* 如果你选择的是和现场环境对接,host要修改为现场环境的ip,https端口默认为443,http端口默认为80.例如10.33.25.22:443 或者10.33.25.22:80
* appKey和appSecret请按照或得到的appKey和appSecret更改.
*/
static {
/*static {
// 代理API网关nginx服务器ip端口
ArtemisConfig.host = "60.3.252.114:10443";
// 秘钥appkey
ArtemisConfig.appKey = "29791064";
// 秘钥appSecret
ArtemisConfig.appSecret = "EArAS02rV0krs1waU5nE";
}
}*/
/**
* 能力开放平台的网站路径
*/
......@@ -90,6 +92,7 @@ public class ArtemisController {
String body = jsonBody.toJSONString();
// post请求application/json类型参数
String result = ArtemisHttpUtil.doPostStringArtemis(path,body,null,null,"application/json",null);
if(StringUtils.isEmpty(result)) throw new CustomException("获取海康平台数据失败");
return AjaxResult.success(JSONObject.parseObject(result));
}
......@@ -117,6 +120,7 @@ public class ArtemisController {
String body = jsonBody.toJSONString();
// post请求application/json类型参数
String result = ArtemisHttpUtil.doPostStringArtemis(path,body,null,null,"application/json",null);
if(StringUtils.isEmpty(result)) throw new CustomException("获取海康平台数据失败");
return AjaxResult.success(JSONObject.parseObject(result));
}
......@@ -144,6 +148,7 @@ public class ArtemisController {
String body = jsonBody.toJSONString();
// post请求application/json类型参数
String result = ArtemisHttpUtil.doPostStringArtemis(path,body,null,null,"application/json",null);
if(StringUtils.isEmpty(result)) throw new CustomException("获取海康平台数据失败");
return AjaxResult.success(JSONObject.parseObject(result));
}
......@@ -171,6 +176,7 @@ public class ArtemisController {
}
String body = jsonBody.toJSONString();
String result = ArtemisHttpUtil.doPostStringArtemis(path,body,null,null,"application/json",null);
if(StringUtils.isEmpty(result)) throw new CustomException("获取海康平台数据失败");
return AjaxResult.success(JSONObject.parseObject(result));
}
......
package com.zehong.web.controller.video;
import com.alibaba.fastjson.JSONObject;
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
import com.hikvision.artemis.sdk.config.ArtemisConfig;
import com.zehong.common.core.domain.AjaxResult;
import com.zehong.system.domain.vo.EventSubscriptionVo;
import com.zehong.system.domain.vo.EventUnSubscriptionVo;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.Map;
/**
* 鸿海海康视频接口
*/
@RestController
@RequestMapping("/honghai/artemis")
public class HonghaiArtemisController {
/**
* 请根据自己的appKey和appSecret更换static静态块中的三个参数. [1 host]
* 如果你选择的是和现场环境对接,host要修改为现场环境的ip,https端口默认为443,http端口默认为80.例如10.33.25.22:443 或者10.33.25.22:80
* appKey和appSecret请按照或得到的appKey和appSecret更改.
*/
static {
// 代理API网关nginx服务器ip端口
ArtemisConfig.host = "60.3.252.114:20443";
// 秘钥appkey
ArtemisConfig.appKey = "20289095";
// 秘钥appSecret
ArtemisConfig.appSecret = "2ESpESEYcMNQsnlmsnec";
}
/**
* 能力开放平台的网站路径
*/
private static final String ARTEMIS_PATH = "/artemis";
/**
* 获取监控点预览取流URL
*/
private static final String GET_PREVIEWURLS = ARTEMIS_PATH + "/api/video/v1/cameras/previewURLs";
/**
* 分页获取监控点资源
*/
private static final String GET_CAMERAS = ARTEMIS_PATH + "/api/resource/v1/cameras";
private static final String VEDIO_CONTROLLING = ARTEMIS_PATH + "/api/video/v1/ptzs/controlling";
/**
* 按事件类型订阅事件
*/
private static final String EVENT_SUBSCIRPTION_BY_ENVENTTYPES = ARTEMIS_PATH + "/api/eventService/v1/eventSubscriptionByEventTypes";
/**
* 按事件类型取消订阅事件
*/
private static final String EVENT_UNSUBSCRIPTION_BY_EVENTTYPES = ARTEMIS_PATH + "/api/eventService/v1/eventUnSubscriptionByEventTypes";
/**
* 获取监控点预览取流URL
* @return
*/
@GetMapping("/getPreviewURLs")
public AjaxResult getPreviewURLs(@RequestParam(value = "cameraIndexCode") String cameraIndexCode){
/**
* 根据API文档可以看出来,这是一个POST请求的Rest接口,而且传入的参数值为一个json
* ArtemisHttpUtil工具类提供了doPostStringArtemis这个函数,一共六个参数在文档里写明其中的意思,因为接口是https,
* 所以第一个参数path是一个hashmap类型,请put一个key-value,query为传入的参数,body为传入的json数据
* 传入的contentType为application/json,accept不指定为null
* header没有额外参数可不传,指定为null
*
*/
Map<String, String> path = new HashMap<String, String>(2) {
{
//根据现场环境部署确认是http还是https
put("https://", GET_PREVIEWURLS);
}
};
JSONObject jsonBody = new JSONObject();
//jsonBody.put("cameraIndexCode", "2a9891a194c24747b277f3ea4836d433");
jsonBody.put("cameraIndexCode", cameraIndexCode);
jsonBody.put("streamType", 0);//0主码流,1子码流
jsonBody.put("protocol", "ws");
jsonBody.put("transmode", 1);
String body = jsonBody.toJSONString();
// post请求application/json类型参数
String result = ArtemisHttpUtil.doPostStringArtemis(path,body,null,null,"application/json",null);
return AjaxResult.success(JSONObject.parseObject(result));
}
/**
* 分页获取监控点资源
* @param pageNo 页码
* @param pageSize 每页条数
* @return
*/
@GetMapping("/getCameras")
public AjaxResult getCameras(@RequestParam("pageNo") int pageNo, @RequestParam("pageSize") int pageSize){
Map<String, String> path = new HashMap<String, String>(2) {
{
//根据现场环境部署确认是http还是https
put("https://", GET_CAMERAS);
}
};
JSONObject jsonBody = new JSONObject();
jsonBody.put("pageNo", pageNo);
jsonBody.put("pageSize", pageSize);
jsonBody.put("treeCode", 0);
String body = jsonBody.toJSONString();
// post请求application/json类型参数
String result = ArtemisHttpUtil.doPostStringArtemis(path,body,null,null,"application/json",null);
return AjaxResult.success(JSONObject.parseObject(result));
}
/**
* 云控操作
* @param cameraIndexCode
* @param command
* @param action
* @return
*/
@RequestMapping("/videoControlling")
public AjaxResult videoControlling(@RequestParam("cameraIndexCode") String cameraIndexCode, @RequestParam("command") String command, @RequestParam("action") String action, @RequestParam("speed") String speed){
Map<String, String> path = new HashMap<String, String>(2) {
{
//根据现场环境部署确认是http还是https
put("https://", VEDIO_CONTROLLING);
}
};
JSONObject jsonBody = new JSONObject();
jsonBody.put("cameraIndexCode", cameraIndexCode);
jsonBody.put("action", action);
jsonBody.put("command", command);
jsonBody.put("speed", speed);
String body = jsonBody.toJSONString();
// post请求application/json类型参数
String result = ArtemisHttpUtil.doPostStringArtemis(path,body,null,null,"application/json",null);
return AjaxResult.success(JSONObject.parseObject(result));
}
/**
* 按事件类型订阅事件
* @param eventSubscriptionVo 事件订阅实体
* @return
*/
@PostMapping("/eventSubscriptionByEventTypes")
public AjaxResult eventSubscriptionByEventTypes(@RequestBody EventSubscriptionVo eventSubscriptionVo){
Map<String, String> path = new HashMap<String, String>(2) {
{
//根据现场环境部署确认是http还是https
put("https://", EVENT_SUBSCIRPTION_BY_ENVENTTYPES);
}
};
JSONObject jsonBody = new JSONObject();
jsonBody.put("eventTypes", eventSubscriptionVo.getEventTypes());
jsonBody.put("eventDest", eventSubscriptionVo.getEventDest());
if(eventSubscriptionVo.getSubType() !=0){
jsonBody.put("subType", eventSubscriptionVo.getSubType());
}
if(null !=eventSubscriptionVo.getEventLvl() && eventSubscriptionVo.getEventLvl().size() != 0){
jsonBody.put("eventLvl", eventSubscriptionVo.getEventLvl());
}
String body = jsonBody.toJSONString();
String result = ArtemisHttpUtil.doPostStringArtemis(path,body,null,null,"application/json",null);
return AjaxResult.success(JSONObject.parseObject(result));
}
/**
* 按事件类型取消订阅
* @param eventUnSubscriptionVo 事件类型
* @return
*/
@PostMapping("/eventUnSubscriptionByEventTypes")
public AjaxResult eventUnSubscriptionByEventTypes(@RequestBody EventUnSubscriptionVo eventUnSubscriptionVo){
Map<String, String> path = new HashMap<String, String>(2) {
{
//根据现场环境部署确认是http还是https
put("https://", EVENT_UNSUBSCRIPTION_BY_EVENTTYPES);
}
};
JSONObject jsonBody = new JSONObject();
jsonBody.put("eventTypes", eventUnSubscriptionVo.getEventTypes());
String body = jsonBody.toJSONString();
String result = ArtemisHttpUtil.doPostStringArtemis(path,body,null,null,"application/json",null);
return AjaxResult.success(JSONObject.parseObject(result));
}
}
......@@ -115,4 +115,17 @@ thirdGasUse:
loginUrl: https://manage.cis.jinka.cn/auth/aggregation/app/login
accessKeyId: 001EE4257BA231B2886F13A1316E7395
accessKeySecret: 6D2053243CA99905179E14FBC93B0985075F4A4B0D1B339400EA1DBEF342F880
meterDetailUrl: https://manage.cis.jinka.cn/rest/v1/query/meter-detail
\ No newline at end of file
meterDetailUrl: https://manage.cis.jinka.cn/rest/v1/query/meter-detail
# 海康服务平台
hikvision:
platforms:
huaxin:
host: 60.3.252.114:10443
app-key: 29791064
app-secret: EArAS02rV0krs1waU5nE
honghai:
host: 60.3.252.114:20443
app-key: 20289095
app-secret: 2ESpESEYcMNQsnlmsnec
\ No newline at end of file
......@@ -115,4 +115,17 @@ thirdGasUse:
loginUrl: https://manage.cis-test.jinka.cn/auth/aggregation/app/login
accessKeyId: 001E146809696F2B6FEC38024015808D
accessKeySecret: E0418F33E4F7F480A8F88F6F3D78C0519096759708A2452DEA0D244E6F184E68
meterDetailUrl: https://manage.cis-test.jinka.cn/rest/v1/query/meter-detail
\ No newline at end of file
meterDetailUrl: https://manage.cis-test.jinka.cn/rest/v1/query/meter-detail
# 海康服务平台
hikvision:
platforms:
huaxin:
host: 60.3.252.114:10443
app-key: 29791064
app-secret: EArAS02rV0krs1waU5nE
honghai:
host: 60.3.252.114:20443
app-key: 20289095
app-secret: 2ESpESEYcMNQsnlmsnec
\ No newline at end of file
......@@ -113,4 +113,17 @@ thirdGasUse:
loginUrl: https://manage.cis-test.jinka.cn/auth/aggregation/app/login
accessKeyId: 001E146809696F2B6FEC38024015808D
accessKeySecret: E0418F33E4F7F480A8F88F6F3D78C0519096759708A2452DEA0D244E6F184E68
meterDetailUrl: https://manage.cis-test.jinka.cn/rest/v1/query/meter-detail
\ No newline at end of file
meterDetailUrl: https://manage.cis-test.jinka.cn/rest/v1/query/meter-detail
# 海康服务平台
hikvision:
platforms:
huaxin:
host: 60.3.252.114:10443
app-key: 29791064
app-secret: EArAS02rV0krs1waU5nE
honghai:
host: 60.3.252.114:20443
app-key: 20289095
app-secret: 2ESpESEYcMNQsnlmsnec
\ No newline at end of file
......@@ -59,6 +59,13 @@
<artifactId>huaxin-system</artifactId>
</dependency>
<!--海康-->
<dependency>
<groupId>com.hikvision.ga</groupId>
<artifactId>artemis-http-client</artifactId>
<version>1.1.3</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.zehong.framework.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import java.util.Map;
@Component
@ConfigurationProperties(prefix = "hikvision")
public class HikvisionProperties {
private Map<String, PlatformConfig> platforms;
public Map<String, PlatformConfig> getPlatforms() {
return platforms;
}
public void setPlatforms(Map<String, PlatformConfig> platforms) {
this.platforms = platforms;
}
/**
* 获取平台配置
* @param platformId 平台
* @return
*/
public HikvisionProperties.PlatformConfig getPlatformConfig(String platformId) {
HikvisionProperties.PlatformConfig config = platforms.get(platformId);
if (config == null) {
throw new IllegalArgumentException("未找到平台: " + platformId);
}
return config;
}
public static class PlatformConfig {
private String host;
private String appKey;
private String appSecret;
public String getHost() {
return host;
}
public void setHost(String host) {
this.host = host;
}
public String getAppKey() {
return appKey;
}
public void setAppKey(String appKey) {
this.appKey = appKey;
}
public String getAppSecret() {
return appSecret;
}
public void setAppSecret(String appSecret) {
this.appSecret = appSecret;
}
}
}
package com.zehong.framework.config;
import com.zehong.framework.interceptor.ArtemisInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
......@@ -24,6 +25,12 @@ public class ResourcesConfig implements WebMvcConfigurer
@Autowired
private RepeatSubmitInterceptor repeatSubmitInterceptor;
private final HikvisionProperties properties;
public ResourcesConfig(HikvisionProperties properties) {
this.properties = properties;
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry)
{
......@@ -41,6 +48,8 @@ public class ResourcesConfig implements WebMvcConfigurer
public void addInterceptors(InterceptorRegistry registry)
{
registry.addInterceptor(repeatSubmitInterceptor).addPathPatterns("/**");
registry.addInterceptor(new ArtemisInterceptor(properties))
.addPathPatterns("/artemis/**"); // 拦截 /artemis 开头的所有请求
}
/**
......
package com.zehong.framework.interceptor;
import com.hikvision.artemis.sdk.config.ArtemisConfig;
import com.zehong.common.utils.StringUtils;
import com.zehong.framework.config.HikvisionProperties;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class ArtemisInterceptor implements HandlerInterceptor {
private final HikvisionProperties properties;
public ArtemisInterceptor(HikvisionProperties properties) {
this.properties = properties;
}
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
String path = request.getRequestURI();
// 只拦截以 /artemis 开头的请求
if (path.contains("/artemis")) {
String platform = request.getParameter("platform");
HikvisionProperties.PlatformConfig config = StringUtils.isNotEmpty(platform) ? properties.getPlatformConfig(platform) : properties.getPlatformConfig("huaxin");
// 设置 ArtemisConfig(需要加锁)
synchronized (ArtemisInterceptor.class) {
// 代理API网关nginx服务器ip端口
ArtemisConfig.host = config.getHost();
// 秘钥appkey
ArtemisConfig.appKey = config.getAppKey();
// 秘钥appSecret
ArtemisConfig.appSecret = config.getAppSecret();
}
}
return true;
}
}
......@@ -53,7 +53,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="createTime != null">#{createTime},</if>
<if test="isDel != null">#{isDel},</if>
<if test="remarks != null">#{remarks},</if>
<if test="videoType != null">videoType,</if>
<if test="videoType != null">#{videoType},</if>
</trim>
</insert>
......
import request from '@/utils/request'
/**
* api根地址
* @type {{"1": "华鑫", "2": "鸿海"}}
*/
const apiBaseConfig = {
'1': "/artemis",
'2': "/honghai/artemis"
};
// 查询视频地址
export function getPreviewURLs(query,type='1') {
export function getPreviewURLs(query) {
return request({
url: apiBaseConfig[type] + '/getPreviewURLs',
url: '/artemis/getPreviewURLs',
method: 'get',
params: query
})
}
// 云台控制
export function videoControlling(query,type='1') {
export function videoControlling(query) {
return request({
url: apiBaseConfig[type] + '/videoControlling',
url: '/artemis/videoControlling',
method: 'get',
params: query
})
......
......@@ -126,7 +126,7 @@ export default {
playVideo(data) {
this.videoName = data.videoName;
this.cameraIndexCode = data.videoResource;
getPreviewURLs({ cameraIndexCode: data.videoResource },data.videoType).then((response) => {
getPreviewURLs({ cameraIndexCode: data.videoResource, platform: data.videoType == '2' ? 'honghai' : 'huaxin'}).then((response) => {
if (response.data.code == "0") {
this.videoOpenNum++;
let url = response.data.data.url;
......@@ -138,6 +138,8 @@ export default {
console.error(e);
}
);
}else{
this.$message.error(response.data.msg)
}
});
},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment