使用python对接海康威视的ISC(iSecureCenter)平台

使用python如何对接ISC平台,获取视频、门禁、停车场等业务数据?

步骤如下:

1、登录海康的开放平台网站:open.hikvision.com,查看对接指南

2、正式开始编码

  1. python导入jar包依赖库,需要导入ISC平台的安全认证库,此步为必须动作
  2. 编码参考如下,示例为获取ISC停车场的所有基础数据,比如停车库、车位号等等
# -*- coding:utf-8 -*-
from jpype import *
import json
import os
import jpype

# 启动 并指定JAR包
jarpath = os.path.join(os.path.abspath('.'), 'D:/PycharmProjects/python_work/venv/jar/artemis-http-client-1.1.2.jar')
dependency = os.path.join(os.path.abspath('.'), 'D:/PycharmProjects/python_work/venv/jar/dependency')
startJVM(jpype.getDefaultJVMPath(), "-ea", "-Djava.class.path=%s" %jarpath, "-Djava.ext.dirs=%s" %dependency)
jpype.java.lang.System.out.println("java_HelloWorld")

# Main()
# wrong   jd = JPackage("jar/artemis-http-client-1.1.2.jar").ArtemisConfig()
#test = JPackage("com.hikvision.artemis.sdk.ArtemisHttpUtil").
JDClass =jpype.JClass("com.hikvision.artemis.sdk.ArtemisHttpUtil") #这说明类在jar包中的目录结构是"com.hikvision.artemis.sdk.ArtemisHttpUtil"
ArtemisHttpUtil = JDClass()
JDClass =jpype.JClass("com.hikvision.artemis.sdk.config.ArtemisConfig")
ArtemisConfig = JDClass()


#STEP1:设置平台参数,根据实际情况,设置host appkey appsecret 三个参数.
ArtemisConfig.host = "ip:443" #artemis网关服务器ip端口
ArtemisConfig.appKey = "xxx"  # 秘钥appkey
ArtemisConfig.appSecret = "xxx" # 秘钥appSecret

#STEP2:设置OpenAPI接口的上下文
# ARTEMIS_PATH = "/artemis"

#STEP3:设置接口的URI地址,得是HashMap
previewURLsApi = jpype.java.util.HashMap()
previewURLsApi.put("https://" , "/artemis/api/resource/v1/park/parkList")
        
#TEP4:设置参数提交方式
contentType = "application/json"

#STEP5:组装请求参数
# JSONObject jsonBody = new JSONObject();
# jsonBody.put("cameraIndexCode", "98177ef634be43bab03de0d00ced980e");
# jsonBody.put("streamType", 0);
# jsonBody.put("protocol", "rtsp");
# jsonBody.put("transmode", 1);
# jsonBody.put("expand", "streamform=ps");
# String body = jsonBody.toJSONString();
jsonBody = {}
body = json.dumps(jsonBody)

#STEP6:调用接口
#python中表示null含义的关键字是None
result = ArtemisHttpUtil.doPostStringArtemis(previewURLsApi,body, None, None, contentType, None)
print(result)
print("接口调用完毕")

你可能感兴趣的:(python)