1. 海康综合安防管理平台介绍
1.1 官网介绍
1.2 个人理解
综合安防管理平台部署之后,有2个系统,一个是综合安防管理平台:是用户端系统,一个是运营中心:是综合安防平台的后台管理系统,可提供api与业务平台对接,实现实时预览、录播回放、语音对讲、报警订阅等功能。
1.3 综合安防管理平台
1.4 运行管理中心系统
通过对接综合安防平台API实现摄像头的实时预览,录播回放,语音对讲,安全帽监测
3.1 运行管理中心创建合作方并授权对应的api权限
3.2 获取合作方的秘钥
说明: 该秘钥是获取api权限的秘钥
3.3 拿到该秘钥,想要调用对应API接口还需要获取某一个摄像头的主键,cameraIndexCode
3.3.1 官网api地址
3.3.2 代码编写
controller
@ApiOperation(value = "分页获取监控点资源") @GetMapping(value = "/GetResource") public String postGetResource() { return cameraService.callPostApiGetResources(); }
sereviceImpl
@Override public String callPostApiGetResources() { 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 paramMap = new HashMap();// post请求Form表单参数 paramMap.put("pageNo", "1"); paramMap.put("pageSize", "20"); String body = JSON.toJSON(paramMap).toString(); Map path = new HashMap(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接口地址
3.4.2 代码编写
controller
@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
@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 paramMap = new HashMap();// post请求Form表单参数 paramMap.put("cameraIndexCode", cameraIndexCode); paramMap.put("streamType", 0); paramMap.put("protocol", protocol); String body = JSON.toJSON(paramMap).toString(); Map path = new HashMap(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; }
返回值
{ "code": "0", "msg": "success", "data": { "url": "rtsp://10.2.145.66:655/EUrl/CLJ52BW" }}
根据返回值中的url,放到vlc播放器中可测试是否正确(点击媒体-打开网络串流)
测试正确,播放正常,把该yrl返回给前端,让前端调用h5播放器,播放该url即可。
来源地址:https://blog.csdn.net/liupantao/article/details/129950713