海康摄像头对接,通过海康综合安防管理平台对接
1. 海康综合安防管理平台介绍
1.1 官网介绍
1.2 个人理解
综合安防管理平台部署之后,有2个系统,一个是综合安防管理平台:是用户端系统,一个是运营中心:是综合安防平台的后台管理系统,可提供api与业务平台对接,实现实时预览、录播回放、语音对讲、报警订阅等功能。
1.3 综合安防管理平台
1.4 运行管理中心系统
2. 需求
通过对接综合安防平台API实现摄像头的实时预览,录播回放,语音对讲,安全帽监测
3. 对接步骤
3.1 运行管理中心创建合作方并授权对应的api权限
3.2 获取合作方的秘钥
说明: 该秘钥是获取api权限的秘钥
3.3 拿到该秘钥,想要调用对应API接口还需要获取某一个摄像头的主键,cameraIndexCode
3.3.1 官网api地址
3.3.2 代码编写
controller
/**
* 调用POST请求类型接口,分页获取监控点资源
*
* @return
*/
@ApiOperation(value = "分页获取监控点资源")
@GetMapping(value = "/GetResource")
public String postGetResource() {
return cameraService.callPostApiGetResources();
}
sereviceImpl
/**
* 调用POST请求类型接口,分页获取监控点资源
* 接口实际url:https://ip:port/artemis/api/resource/v1/cameras
*
* @return
*/
@Override
public String callPostApiGetResources() {
/**
* https://ip:port/artemis/api/resource/v1/cameras
* 过查阅AI Cloud开放平台文档或网关门户的文档可以看到分页获取监控点资源的定义,这是一个POST请求的Rest接口, 入参为JSON字符串,接口协议为https。
* ArtemisHttpUtil工具类提供了doPostStringArtemis调用POST请求的方法,入参可传JSON字符串, 请阅读开发指南了解方法入参,没有的参数可传null
*/
ArtemisConfig config = new ArtemisConfig();
config.setHost(artemisHost); // 代理API网关nginx服务器ip端口
config.setAppKey(artemisAppKey); // 秘钥appkey
config.setAppSecret(artemisAppSecret);// 秘钥appSecret
String getCamsApi = ARTEMIS_PATH + "/api/resource/v1/cameras";
Map<String, String> paramMap = new HashMap<String, String>();// post请求Form表单参数
paramMap.put("pageNo", "1");
paramMap.put("pageSize", "20");
String body = JSON.toJSON(paramMap).toString();
Map<String, String> path = new HashMap<String, String>(2) {
{
put("https://", getCamsApi);
}
};
String result = null;
try {
result = ArtemisHttpUtil.doPostStringArtemis(config, path, body, null, null, "application/json");
log.info(MessageFormat.format("分页获取监控点资源{0}", result));
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
返回值
{
"code": "0",
"msg": "success",
"data": {
"total": 1,
"pageNo": 1,
"pageSize": 100,
"list": [
{
"cameraIndexCode": "a8f74dcf14f846bb95c8dff6684f897e",
"cameraName": "193GB_IPCamera 01",
"cameraType": 0,
"cameraTypeName": "1",
"capabilitySet": "645f0a62-05ff-4396-a687-944c3f0406d6",
"capabilitySetName": "0",
"intelligentSet": "0",
"intelligentSetName": "null",
"channelNo": "1",
"channelType": "analog",
"channelTypeName": "null",
"createTime": "null",
"encodeDevIndexCode": "73c2e4903a4547f8812a26d329802cd0",
"encodeDevResourceType": "null",
"encodeDevResourceTypeName": "null",
"gbIndexCode": "null",
"installLocation": "29",
"keyBoardCode": "ga_h264",
"latitude": "null",
"longitude": "null",
"pixel": 1,
"ptz": 1,
"ptzController": 1,
"ptzControllerName": "123",
"ptzName": "1234",
"recordLocation": "0",
"recordLocationName": "0",
"regionIndexCode": "123",
"status": 1,
"statusName": "123",
"transType": 0,
"transTypeName": "1",
"treatyType": "1",
"treatyTypeName": "1",
"viewshed": "123",
"updateTime": "1234567489"
}
]
}
}
拿到对应的摄像头的主键cameraIndexCode,保存到数据库,后面调用实时预览接口,对应哪一个摄像头设备,用到这个cameraIndexCode
3.4 拿到该秘钥,就可以调用对应的实时预览接口,获取实时预览的串流url
3.4.1 官网api接口地址
https://open.hikvision.com/docs/docId?productId=5c67f1e2f05948198c909700&version=%2Ff8356830af1d40f3b1da7db12baa47af&tagPath=API%E5%88%97%E8%A1%A8-%E8%A7%86%E9%A2%91%E4%B8%9A%E5%8A%A1-%E8%A7%86%E9%A2%91%E5%8A%9F%E8%83%BD#c93b92ea
3.4.2 代码编写
controller
/**
* 调用POST请求类型接口,获取当前监控点的预览url
*
* @return
*/
@ApiOperation(value = "获取当前监控点的预览url")
@GetMapping(value = "/getOnePreviewUrl")
public AjaxResult getOnePreviewUrl(@RequestParam(value = "cameraIndexCode") String cameraIndexCode) {
String url = cameraService.callPostApiPreviewUrl(cameraIndexCode, "rtmp");
return AjaxResult.successData(url);
}
serviceImpl
/**
* 调用POST请求类型接口,获取监控点预览取流URL
* 接口实际url:https://ip:port/artemis/api/resource/v1/cameras
*
* @return
*/
@Override
public String callPostApiPreviewUrl(String cameraIndexCode, String protocol) {
ArtemisConfig config = new ArtemisConfig();
config.setHost(artemisHost); // 代理API网关nginx服务器ip端口
config.setAppKey(artemisAppKey); // 秘钥appkey
config.setAppSecret(artemisAppSecret);// 秘钥appSecret
String getCamsApi = ARTEMIS_PATH + "/api/video/v1/cameras/previewURLs";
Map<String, Object> paramMap = new HashMap<String, Object>();// post请求Form表单参数
paramMap.put("cameraIndexCode", cameraIndexCode);
paramMap.put("streamType", 0);
paramMap.put("protocol", protocol);
String body = JSON.toJSON(paramMap).toString();
Map<String, String> path = new HashMap<String, String>(2) {
{
put("https://", getCamsApi);
}
};
String result = null;
try {
result = ArtemisHttpUtil.doPostStringArtemis(config, path, body, null, null, "application/json");
log.info(MessageFormat.format("获取监控点预览取流URL{0}", result));
JSONObject jsonObject = JSON.parseObject(result);
String code = jsonObject.getString("code");
if("0".equals(code)){
String data = jsonObject.getString("data");
return data;
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
返回值文章来源:https://www.toymoban.com/news/detail-456094.html
{
"code": "0",
"msg": "success",
"data": {
"url": "rtsp://10.2.145.66:655/EUrl/CLJ52BW"
}
}
根据返回值中的url,放到vlc播放器中可测试是否正确(点击媒体-打开网络串流)
测试正确,播放正常,把该yrl返回给前端,让前端调用h5播放器,播放该url即可。文章来源地址https://www.toymoban.com/news/detail-456094.html
到了这里,关于海康 综合安防管理平台 对接的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!