对接海康监控
1. 配置
开发文档地址
https://综合安防平台ip/artemis-portal/document/0
1.1 获取监控凭证
登录综合安防管理平台
设备管理=> 视频=> 监控点
找到对应摄像头,点击修改
复制出=>监控点编码,即可
将监控的ip与监控点编号关系存储在本地数据库或者缓存
1.2 更换监控码流
登录监控https://监控ip/doc/page/config.asp
1.3 常见问题
以摄像头152为例
排查1: 登录摄像头配置页面 访问=> https://10.18.153.152/doc/page/config.asp,检查是否有视频,无:找施工人员反馈问题
排查2: 登录综合安防管理平台,检查是否添加到平台及播放情况,正常进入下一步,否则找施工人员反馈问题
排查3: 检查马流是否配置一致
问题解决:马流未配置正常
2. 代码
2.1 获取监控码流
依赖
引入本地jar包,资源自行下载
<dependency>
<groupId>com.hikvision</groupId>
<artifactId>artemis</artifactId>
<version>2.2.2</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/libs/artemis-http-client-1.1.7.jar</systemPath>
</dependency>
打包运行报错添加打包方式
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.2.0</version>
<executions>
<!--将scope为system的jar包打包进可执行jar包-->
<execution>
<id>copy-jars</id>
<!--指定在 Maven 构建过程中的 prepare-package 阶段执行-->
<phase>prepare-package</phase>
<goals>
<!--指定需要完成的具体任务-->
<goal>copy-resources</goal>
</goals>
<!--配置插件执行的具体参数,包括输入输出目录、文件过滤规则、资源过滤规则等等-->
<configuration>
<!--指定输出目录(以下目录就是打包后的可执行jar包里的依赖目录)-->
<outputDirectory>${project.build.outputDirectory}/BOOT-INF/lib</outputDirectory>
<!--定义要复制的资源文件-->
<resources>
<resource>
<directory>${project.basedir}/src/main/resources/libs</directory>
<includes>
<include>*.jar</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
yml
配置
# 海康监控配置
hk:
host: 综合安防平台ip
appkey: 综合安防平台获取
appsecret: 综合安防平台获取
根据监控凭证获取视频码流
package com.chery.project.control.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.chery.common.constant.Constants;
import com.chery.common.enums.ProtocolType;
import com.chery.common.utils.DictUtils;
import com.chery.common.utils.StringUtils;
import com.chery.framework.redis.RedisCache;
import com.chery.project.control.bo.Monitor;
import com.chery.project.control.bo.Result;
import com.chery.project.control.service.HiKiService;
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
import com.hikvision.artemis.sdk.config.ArtemisConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;
/**
* 海康服务
*/
@Service
public class HiKiServiceImpl implements HiKiService {
public final static String HI_KI_STATION_VOUCHER = "hiki_station_voucher";
// private static String ARTEMIS_PATH = "/artemis";
private static String contentType = "application/json";
final String previewURLsApi = "/artemis/api/video/v2/cameras/previewURLs";
Map<String, String> path = new HashMap<String, String>(2) {
{
put("https://", previewURLsApi);//根据现场环境部署确认是http还是https
}
};
@Value("${hk.host}")
private String host;
@Value("${hk.appkey}")
private String appkey;
@Value("${hk.appsecret}")
private String appsecret;
@Autowired
private RedisCache redisCache;
/**
* 根据监控ip获取码流
*
* @param ip
* @return
*/
@Override
public Monitor getStreamFlowByIp(String ip) {
//获取凭证
final String soundPostId = DictUtils.getDictValue(HI_KI_STATION_VOUCHER, ip);
final Result video = getVideo(soundPostId, ProtocolType.HLS, "streamform=ps");
return video.getData();
}
/**
* 根据监控凭证获取视频码流
* @param soundPostId
* @param protocolType
* @param expandStr
* @return
*/
public Result getVideo(String soundPostId, ProtocolType protocolType, String expandStr){
ArtemisConfig artemisConfig = new ArtemisConfig();
artemisConfig.setHost(host);
artemisConfig.setAppKey(appkey);
artemisConfig.setAppSecret(appsecret);
JSONObject jsonBody = new JSONObject();
Result result = new Result();
jsonBody.put("streamType", 0);
jsonBody.put("protocol", protocolType.value());
jsonBody.put("transmode", 1);
jsonBody.put("expand", expandStr);
String resultString = null;// post请求application/json类型参数
System.out.println("soundPostId::"+soundPostId);
if (StringUtils.isNotEmpty(soundPostId)) {
jsonBody.put("cameraIndexCode", soundPostId);
String body = jsonBody.toJSONString();
try {
resultString =
ArtemisHttpUtil.doPostStringArtemis(artemisConfig,
path, body, null, null, contentType, null);
System.out.println(soundPostId+":调用接口情况:"+resultString);
} catch (Exception e) {
System.out.println("异常节点.soundPostId="+soundPostId);
throw new RuntimeException(e);
}
JSONObject jsonObject = JSONObject.parseObject(resultString);
result = JSON.toJavaObject(jsonObject, Result.class);
if (result.getData() != null) {
if (StringUtils.isNotEmpty(result.getCode())) {
result.getData().setCode(result.getCode());
}
if (StringUtils.isNotEmpty(result.getMsg())) {
result.getData().setMsg(result.getMsg());
}
}
}
return result;
}
}