Files
SupervisorAI/utils/hikvision_cam_utils.py

52 lines
1.8 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import requests
import urllib3
from hikvision_openapi_signer import HikvisionOpenAPISigner
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
# 初始化签名器
signer = HikvisionOpenAPISigner(
"https://29.2.19.19:443",
"28031410",
"Y79rv6LqBahxoEH6adLv",
headers={'tagId': '0'} # 根据平台要求设置
)
def get_organization_list(parentIndexCode):
# 签名一个请求
request = signer.sign(
'POST',
'/api/resource/v1/regions/subRegions',
jsons={'parentIndexCode': parentIndexCode, 'treeCode': '0'},
accept='application/json'
)
method, url, headers, body = request
# 发送请求
response = requests.request(method, url, headers=headers, data=body, verify=False)
return response.json()
def get_final_list(regionIndexCode):
# 签名一个请求
request = signer.sign(
'POST',
'/api/resource/v1/regions/regionIndexCode/cameras',
jsons={'pageNo': 1, 'pageSize': 100, 'regionIndexCode': regionIndexCode, 'treeCode': '0'},
accept='application/json'
)
method, url, headers, body = request
# 发送请求注意离线环境下verify=False可能必要但需知安全风险
response = requests.request(method, url, headers=headers, data=body, verify=False)
return response.json()
def get_camera_preview_url(camera_index_code, stream_type = 0):
# 签名一个请求
request = signer.sign(
'POST',
'/api/video/v1/cameras/previewURLs',
jsons={'cameraIndexCode': camera_index_code, 'protocol': 'hls', 'streamType': stream_type, 'expand': 'transcode=1'},
accept='application/json'
)
method, url, headers, body = request
# 发送请求
response = requests.request(method, url, headers=headers, data=body, verify=False)
return response.json()