目录
2. 登录运管中心,获取海康安防平台 ( AppKey,App_Secret)
6. 时效性rtsp流生成 (该功能是把资源监控点编号参数传进去,生成时效性rtsp流)
本文介绍了如何通过接口与海康综合安防管理平台进行数据交互,获取平台中的区域信息、监控点数据以及时效性 RTSP 流。通过调用平台的 API,我们能够有效地获取和管理安防系统中的各类资源,支持多种数据类型的获取与分析,进而为平台的监控、管理与调度提供数据支持。
一 . 开发准备
1. 海康安防平台OpenApi参考文档地址
https://open.hikvision.com/docs/docId?version=%2F29c78ef52ca842c7933bd2b8e051e9d0&tagPath=%E6%96%87%E6%A1%A3%E8%AF%B4%E6%98%8E
2. 登录运管中心,获取海康安防平台 ( AppKey,App_Secret)
二. 下载 OpenAPI安全认证库(Python)
1. OpenAPI安全认证库-Python版本下载
目前官网没有提供 Python认证库,大家可以点击下方网盘链接下载
OpenAPI安全认证库zip下载链接https://pan.baidu.com/s/1IVi3ZMM2XVIfFF8QTibWSg?pwd=0205%C2%A0
2. AK \ SK认证
接口鉴权统一使用AK\SK认证,其中AK\SK是通过API网关发放的。AK\SK摘要认证方案如下
# -*- coding: UTF-8 -*-
import hashlib
import hmac
import base64
import time
import uuid
import requests
import json
#Step1:配置host地址、端口号、appKey和appSecret
# api config
host ='https://192.168.139.246'
port ='443'
artemis='artemis'
appKey = '24481068'
appSecret = 'wTdNalUIHRlN5ZknxWzc'
methon = 'POST'
# 请求头构造
def Signature(appSecret,methon,appKey,artemis,api):
## Timestamp
t = time.time()
nowTime = lambda:int(round(t * 1000))
timestamp=nowTime()
timestamp=str(timestamp)
# uuid
nonce= str(uuid.uuid1())
#signature
secret=str(appSecret).encode('utf-8')
message = str(methon+'\n*/*\napplication/json\nx-ca-key:'+appKey+'\nx-ca-nonce:'+nonce+'\nx-ca-timestamp:'+timestamp+'\n/'+artemis+api).encode('utf-8')
signature = base64.b64encode(hmac.new(secret, message, digestmod=hashlib.sha256).digest())
# print(signature)
#header
header_dict = dict()
header_dict['Accept'] = '*/*'
header_dict['Content-Type'] = 'application/json'
header_dict['X-Ca-Key'] = appKey
header_dict['X-Ca-Signature'] = signature
header_dict['X-Ca-timestamp'] = timestamp
header_dict['X-Ca-nonce'] = nonce
header_dict['X-Ca-Signature-Headers'] = 'x-ca-key,x-ca-nonce,x-ca-timestamp'
# print (header_dict)
return header_dict
3. 查询安防平台区域列表v2(区域)
根据查询条件查询区域列表信息,主要用于区域信息查询过滤。
相对V1接口,支持级联场景的区域查询
(1)请求示例代码如下
# -*- coding: UTF-8 -*-
import hashlib
import hmac
import base64
import time
import uuid
import requests
import json
#Step1:配置host地址、端口号、appKey和appSecret
# api config
host ='https://192.168.139.246'
port ='443'
artemis='artemis'
appKey = '24481068'
appSecret = 'wTdNalUIHRlN5ZknxWzc'
methon = 'POST'
# 请求头构造
def Signature(appSecret,methon,appKey,artemis,api):
## Timestamp
t = time.time()
nowTime = lambda:int(round(t * 1000))
timestamp=nowTime()
timestamp=str(timestamp)
# uuid
nonce= str(uuid.uuid1())
#signature
secret=str(appSecret).encode('utf-8')
message = str(methon+'\n*/*\napplication/json\nx-ca-key:'+appKey+'\nx-ca-nonce:'+nonce+'\nx-ca-timestamp:'+timestamp+'\n/'+artemis+api).encode('utf-8')
signature = base64.b64encode(hmac.new(secret, message, digestmod=hashlib.sha256).digest())
# print(signature)
#header
header_dict = dict()
header_dict['Accept'] = '*/*'
header_dict['Content-Type'] = 'application/json'
header_dict['X-Ca-Key'] = appKey
header_dict['X-Ca-Signature'] = signature
header_dict['X-Ca-timestamp'] = timestamp
header_dict['X-Ca-nonce'] = nonce
header_dict['X-Ca-Signature-Headers'] = 'x-ca-key,x-ca-nonce,x-ca-timestamp'
# print (header_dict)
return header_dict
# 获取安防平台视频区域信息
def get_video_area():
"""
'code': '0', 状态码
'msg': 'success', 请求成功
'data': {'total': 12, 'pageNo': 1, 'pageSize': 1000, 'list': [] } 数据
:return:
"""
payload = {
"pageNo": 1,
"pageSize": 1000,
"resourceType": 'region',
# 传region时查询的为用户有配置权限的区域树,
# 传资源类型如:camera、encodeDevice查询用户对该类资源有权限的区域树;
}
api = '/api/irds/v2/region/nodesByParams'
url = host + ':' + port + '/' + artemis + api
data = requests.post(url, headers=Signature(appSecret,methon,appKey,artemis,api), json=payload,verify=False)
return json.loads(data.text)['data']['list']
print(get_video_area())