OpenAPI安全认证库 (Java)开发指南V1.1.7

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

Machine Translated by Google

OpenAPI Security Authentication Library (Java)

Development Guide V1.1.7

Prepared by Li Chao39

Approved by Chen Zhe 8


Machine Translated by Google

1 Introduction

1.1 Preface

Thank you very much for using our company's products, we will do our best to provide you with the best service. this manual

May contain technical inaccuracies or typographical errors. The contents of this manual will be updated regularly without

Further notice, the updated content will be added in the new version of this manual. We may improve or update this book at any time

product or procedure described in the manual.

When you read this development guide, you should also have the files listed in Table 1.2-1. file functions such as

The following table:

Table 1.2-1 Document List

file name describe

Develop reference sample code, such as getting a list of organizations and getting

ArtemisPostTest.java
Two POST request interface calls to get the list of regions.

OpenAPI Security Authentication Library (Java) Development Guide A development guide for using the OpenAPI Secure Authentication Library (Java), i.e.

South Vx.xxpdf this document.

It encapsulates the dependent JAR files for the security authentication and signature work. Development requires

artemis-http-client-x.x.x.jar
to be introduced into the project.

readme.txt A brief description of the results, which must be read before development.

Unzip the OpenAPI security authentication library (java) product, its directory structure is as follows:

ÿÿdemo

ÿ
ÿÿArtemisPostTest.java

ÿÿdoc

ÿ
ÿÿOpenAPI Security Authentication Library (Java) Development Guide Vx.xxpdf

ÿÿartemis-http-client-x.x.x.jar

ÿÿreadme.txt
Machine Translated by Google

1.2 Introduction to OpenAPI Security Authentication Library (Java)

The OpenAPI security authentication library encapsulates the POST and GET methods of HTTP/HTTPS, providing

Java calls the unified entry of OpenAPI HTTP interface. OpenAPI security authentication library blocked

OpenAPI HTTP interface signature details, reducing the complexity of Java docking OpenAPI, the user

Just introduce OpenAPI Security Authentication Library ( Java ÿ You can easily and quickly implement OpenAPI HTTP connection

mouth call.

1.3 Operating Environment

ÿ JDK8 and above.

1.4 Update Instructions

ÿ V1.1.7

Fixed a large number of CLOSE_WAIT connection problems;

Provides an example of getting a picture.

ÿ V1.1.6

Support file upload type interface calls; upgrade third-party libraries to solve security vulnerabilities.

ÿ V1.1.5

Supports calling with multiple sets of AKSK.

ÿ V1.1.4

Upgrade third-party libraries to address security vulnerabilities.

ÿ V1.1.3

Modify JDK1.7 to support https protocol calls.

ÿ V1.1.2

Modify the static list in the request and throw ConcurrentModificationException during concurrent access

unusual question.

ÿ V1.1.1

The code compilation version is changed to 1.6, which supports the use of jdk1.6 for development.

ÿ V1.1.0
Machine Translated by Google

The OpenAPI security authentication library (Java) code is open source, which can be imported through the public network maven dependency.

ÿ V1.0.0

Solve the problem that the image downloaded from the https address does not ignore the authentication.

2 Interface description

2.1 Calling steps

2.1.1 Call Description

OpenAPI Security Authentication Library (Java) maven dependency coordinates:

<dependency>

<groupId>com.hikvision.ga</groupId>

<artifactId>artemis-http-client</artifactId>

<version>1.1.6</version>

</dependency>

Please import the artemis-http-client.jar package before development.

All encapsulated Post and Get methods are in the ArtemisHttpUtil class. Please refer to 2.1.2 Initialization Parameters

Explain the assignment of parameters, and then directly call OpenAPI through the static method provided by the ArtemisHttpUtil class

HTTP interface, method signature, please refer to 2.2 Method Definition section.

2.1.2 Initialization parameters

Before calling the interface, please contact Hikvision technical support to obtain information about the caller's access to the platform, including

The platform IP, port, and the caller correspond to the partner's partner Key and partner's Secret.

Platform initialization parameters are set by setting the static properties of the ArtemisConfig class. ArtemisConfig

There are three properties, part of the source code is as follows:

ArtemisConfig {

public String host;

public String appKey;

public String;
Machine Translated by Google

The properties in the ArtemisConfig class have the following meanings:

parameter data whether describe

name type must pass

host String true The host format is IP:Port, such as 10.0.0.1:443.

When the interface is called using the https protocol, the IP is the platform (nginx) IP, Port

is the port of the https protocol;

When using the http protocol to call the interface, the IP is the IP of the artemis service , and the Port

is the port of the artemis service (default 9016).

Please configure according to the actual situation.

appKey String true assigns the partner's partner Key parameter to the caller

appSecret String true Assign the partner's partner Secret parameter to the caller

Parameter initialization sample code:

ArtemisConfig artemisConfig = new ArtemisConfig();

artemisConfig.setHost("10.0.0.1:443"); //Platform (nginx) IP and port

artemisConfig.setAppKey("11111111"); //Partner key

artemisConfig.setAppSecret("AAAAAAAAAAAAA");//Partner Secret

The caller selects the appropriate method in the method definition in 2.2 according to the interface request parameters and Method type to be called.

method.

2.1.3 Unified description of method parameters

The uniform specification of method parameters applies to all interfaces.

2.1.3.1 Path parameter description

The path parameter of all methods is a HashMap collection that only stores one set of data, that is, the path parameter

Only one Key-Value key-value pair is stored.

Key: interface protocol, the format is http request protocol + "://";

Value: interface path, the format is the context of the API gateway backend service + the request of the OpenAPI interface

Find path.

The protocol of the http request refers to the protocol of the OpenAPI interface (HTTP/HTTPS);
Machine Translated by Google

The context of the API Gateway backend service (artemis) is "/artemis",

The request path of the OpenAPI interface is the request path provided by the interface configured in the API gateway.

Example code to set the path parameter:

final String getSecurityApi = "/artemis" + "/api/hello/v1/headget"; // interface path

Map<String, String> path = new HashMap<String, String>(2) {

put("https://", getSecurityApi); //Key is the protocol, Value is the interface path

};

2.1.3.2 query parameter description

query refers to the parameters in the request address, that is, the query parameters in the request url.

If the request url is "https://10.0.0.1:443/artemis/api?aa=CC&bb=DD", the query parameters

For "aa=CC&bb=DD", when the method call encapsulates the query parameter, the key-value pair of Key=Value needs to be

Stored in Map.

Example code for setting the query parameter "aa=CC&bb=DD" in the request address:

Map<String,String> queries = new HashMap<String,String>();//Query parameters for post request

querys.put(“aa”, “CC”);

querys.put(“bb”, “DD”);

2.1.3.3 Interface call timeout setting

Constant class Constants (fully qualified class name: com.hikvision.artemis.sdk.constant.Constants)

The DEFAULT_TIMEOUT static property can be used to set the timeout time of the method call in milliseconds

seconds. Before the interface is called, the timeout period of the interface call can be set through this property, for example:

Constants. DEFAULT_TIMEOUT = 10000

In the example, the call timeout of the setting method is 10 seconds.

2.1.3.4 parameter description of artemisConfig

The artemisConfig contains the requested host, appKey and appSecret.

If the request url is "https://10.0.0.1:443/artemis/api/x/x/x", you need to change the artemisConfig


Machine Translated by Google

The host parameter is set to 10.0.0.1:443, and the appKey parameter of artemisConfig is set to the partner's

AK, set the appSecret parameter of artemisConfig to the SK of the partner used.

ArtemisConfig artemisConfig = new ArtemisConfig(“10.10.10.1:443”, “11111111”,

“AAAAAAAAAAAAAA”);

2.2 Interface Definition

This section introduces the meaning of static methods and parameters provided in the ArtemisHttpUtil class, and provides sample code

For the caller's reference.

2.2.1 doGetArtemis (without header parameter)

Encapsulates get requests without header parameters.

2.1.1.1 Method Signature

public static String doGetArtemis(ArtemisConfig artemisConfig,Map<String, String> path,

Map<String, String> querys, String accept, String contentType);

2.1.1.2 Parameter meaning

parameter data whether describe

name type Required

artemisConfi Objec true request host, partner ak/sk package class

g t

path The path requested by Map true, the format is as described in 2.1.3.1 path parameter description.

querys Map false The query parameter of the request url, the format refers to the description of 2.1.3.2 query parameter.

accept String false specifies the data type that the client can receive. When this parameter is empty, it is set by default.

set to receive all types.

contentType String false The media type of the request entity body, this parameter is set to the default value when empty

application/textÿ
Machine Translated by Google

2.1.1.3 Example

public static void main(String[] args) {

ArtemisConfig artemisConfig = new ArtemisConfig();

artemisConfig.setHost("10.0.0.1:443"); //Platform (nginx) IP and port

artemisConfig.setAppKey("11111111"); //Partner key

artemisConfig.setAppSecret("AAAAAAAAAAAA");//Partner Secret final String getSecurityApi = "/

artemis" + "/api/hello/v1/headget"; // Interface path

Map<String, String> path = new HashMap<String, String>(2) {

put(“https://”, getSecurityApi);

};

Map<String,String> queries = new HashMap<String,String>();//get request query parameters

querys.put(“start”, “0”);

querys.put(“size”, “20”);

String result = ArtemisHttpUtil.doGetArtemis(artemisConfig,path, querys, null, null);

System.out.println(result);

2.2.2 doGetArtemis (with header parameter)

A get request encapsulated with header parameters.

2.2.2.1 Method Signature

public static String doGetArtemis(ArtemisConfig artemisConfig,Map<String, String> path,

Map<String, String> querys, String accept, String contentType, Map<String, String> header);

2.2.2.2 Parameter meaning

parameter data whether describe

name type Required

artemisConfi Object true Request host, partner ak/sk package class, format refer to 2.1.3.4

g artemisConfig parameter description


Machine Translated by Google

path The path requested by Map true, the format is as described in 2.1.3.1 path parameter description.

querys Map false The query parameter of the request url, the format refers to the description of 2.1.3.2 query parameter.

accept String false specifies the data type that the client can receive, the default setting when this parameter is empty

Receive all types.

contentType String false The media type of the request entity body, this parameter is set to the default value when empty

application/textÿ

header The header parameter of the Map false request needs to be in key-value pair format.

2.2.2.3 Example

public static void main(String[] args) {

ArtemisConfig artemisConfig = new ArtemisConfig();

artemisConfig.setHost("10.0.0.1:443"); //Platform (nginx) IP and port

artemisConfig.setAppKey("11111111"); //Partner key

artemisConfig.setAppSecret("AAAAAAAAAAAA");//Partner Secret

final String getSecurityApi = "/artemis" + "/api/hello/v1/headget"; // interface path

Map<String, String> path = new HashMap<String, String>(2) {

put(“https://”, getSecurityApi);

};

Map<String, String> head = new HashMap<String, String>(2) { //get the header parameter of the request

put(“headget”, “sky-test”);

};

Map<String,String> queries = new HashMap<String,String>();//get request query parameters

querys.put(“start”, “0”);

querys.put(“size”, “20”);

String result = ArtemisHttpUtil.doGetArtemis(artemisConfig ,path, querys, null, null,head);

System.out.println(result);

}
Machine Translated by Google

2.2.3 doPostFormArtemis (without header parameter)

Encapsulates a post form type request without header parameters, and the request parameters include query parameters and form forms

parameter.

2.2.3.1 Method Signature

public static String doPostFormArtemis(ArtemisConfig artemisConfig, Map<String, String> path,

Map<String, String> paramMap, Map<String, String> querys, String accept, String contentType);

2.2.3.2 Parameter meaning

parameter data whether describe

name type Required

artemisConfi Object true Request host, partner ak/sk package class, format refer to 2.1.3.4

g artemisConfig parameter description

path The path requested by Map true, the format is as described in 2.1.3.1 path parameter description.

paramMap Map false form The parameter of the form request, which needs to be set in key-value pair format.

querys Map false The query parameter of the request url, the format refers to the description of 2.1.3.2 query parameter.

accept String false specifies the data type that the client can receive, the default setting when this parameter is empty

Receive all types.

contentType String false The media type of the request entity body, this parameter is set to the default value when empty

application/textÿ

2.2.3.2 Example

public static void main(String[] args) {

ArtemisConfig artemisConfig = new ArtemisConfig();

artemisConfig.setHost("10.0.0.1:443"); //Platform (nginx) IP and port

artemisConfig.setAppKey("11111111"); //Partner key

artemisConfig.setAppSecret("AAAAAAAAAAAA");//Partner Secretfinal

String getSecurityApi = "/artemis" + "/api/hello/v1/headget"; // interface path

Map<String, String> path = new HashMap<String, String>(2) {


Machine Translated by Google

put(“https://”, getSecurityApi);

};

Map<String,String> queries = new HashMap<String,String>();//Query parameters for post request

querys.put(“start”, “0”);

querys.put(“size”, “20”);

String result = ArtemisHttpUtil.doPostFormArtemis(artemisConfig, path, null, querys,

null,null);

System.out.println(result);

2.2.4 doPostFormArtemis (with header parameter)

A post form type request encapsulated with header parameters, the request parameters include query parameters and form forms

parameter.

2.2.4.1 Method Signature

public static String doPostFormArtemis(ArtemisConfig artemisConfig, Map<String, String> path,

Map<String, String> paramMap, Map<String, String> querys, String accept, String contentType,

Map<String, String> header);

2.2.4.2 Parameter meaning

parameter data whether describe

name type Required

artemisConfi Object true Request host, partner ak/sk package class, format refer to 2.1.3.4

g artemisConfig parameter description

path The path requested by Map true, the format is as described in 2.1.3.1 path parameter description.

paramMap Map false form The parameter of the form request, which needs to be set in key-value pair format.

querys Map false The query parameter of the request url, the format refers to the description of 2.1.3.2 query parameter.

accept String false specifies the data type that the client can receive, the default setting when this parameter is empty
Machine Translated by Google

Receive all types.

contentType String false The media type of the request entity body, this parameter is set to the default value when empty

application/textÿ

header The header parameter of the Map false request needs to be in key-value pair format.

2.2.4.3 Example

public static void main(String[] args) {

ArtemisConfig artemisConfig = new ArtemisConfig();

artemisConfig.setHost("10.0.0.1:443"); //Platform (nginx) IP and port

artemisConfig.setAppKey("11111111"); //Partner key

artemisConfig.setAppSecret("AAAAAAAAAAAA");//Partner Secret

final String getSecurityApi = "/artemis" + "/api/hello/v1/headget"; // interface path

Map<String, String> path = new HashMap<String, String>(2) {

put(“https://”, getSecurityApi);

};

Map<String, String> head = new HashMap<String, String>(2) { //header parameter of post request

put(“headpost”, “sky-test”);

};

Map<String,String> queries = new HashMap<String,String>();//Query parameters for post request

querys.put(“start”, “0”);

querys.put(“size”, “20”);

String result = ArtemisHttpUtil.doPostFormArtemis(artemisConfig, path, null, querys,

null,null,head);

System.out.println(result);

2.2.5 doPostStringArtemis (without header parameter)

Encapsulates a post type request without header parameters, and the request body is a json string.
Machine Translated by Google

2.2.5.1 Method Signature

public static String doPostStringArtemis(ArtemisConfig artemisConfig, Map<String, String> path,

String body, Map<String, String> querys, String

accept, String contentType);

2.2.5.2 Parameter meaning

parameter data whether describe

name type Required

artemisConfi Object true Request host, partner ak/sk package class, format refer to 2.1.3.4

g artemisConfig parameter description

path The path requested by Map true, the format is as described in 2.1.3.1 path parameter description.

body String false A request parameter in JSON format, which needs to be converted to a string.

querys Map false The query parameter of the request url, the format refers to the description of 2.1.3.2 query parameter.

accept String false specifies the data type that the client can receive, the default setting when this parameter is empty

Receive all types.

contentType String false The media type of the request entity body, this parameter is set to the default value when empty

application/text, when this method is called, application/json is passed.

2.2.5.3 Example

public static void main(String[] args) {

ArtemisConfig artemisConfig = new ArtemisConfig();

artemisConfig.setHost("10.0.0.1:443"); //Platform (nginx) IP and port

artemisConfig.setAppKey("11111111"); //Partner key

artemisConfig.setAppSecret("AAAAAAAAAAAAA");//Partner Secret

final String getSecurityApi = "/artemis" + "/api/hello/v1/headget"; // interface path

Map<String, String> path = new HashMap<String, String>(2) {

put(“https://”, getSecurityApi);

};
Machine Translated by Google

JSONObject jsonBody = new JSONObject();

jsonBody.put(“deviceCodes”,”-1”);

jsonBody.put(“sex”,-1);

jsonBody.put("beginDate",,"2017-09-01 12:00:00");

jsonBody.put(“endDate”,”2017-09-12 12:00:00”);

String body = jsonBody.toJSONString();

String result = ArtemisHttpUtil.doPostStringArtemis(artemisConfig, path, body, null,

null,”application/json”);

System.out.println(result);

2.2.6 doPostStringArtemis (with header parameter)

A post type request encapsulated with header parameters, the request body is a json string.

2.2.6.1 Method Signature

public static String doPostStringArtemis(ArtemisConfig artemisConfig, Map<String, String> path,

String body, Map<String, String> querys, String

accept, String contentType, Map<String, String> header) ;

2.2.6.2 Parameter meaning

parameter data whether describe

name type Required

artemisConfi Object true Request host, partner ak/sk package class, format refer to 2.1.3.4

g artemisConfig parameter description

path The path requested by Map true, the format is as described in 2.1.3.1 path parameter description.

body Map false Request parameters in JSON format, which need to be converted to strings.

querys Map false The query parameter of the request url, the format refers to the description of 2.1.3.2 query parameter.

accept String false specifies the data type that the client can receive, the default setting when this parameter is empty

Receive all types.

contentType String false The media type of the request entity body, this parameter is set to the default value when empty
Machine Translated by Google

application/text, when this method is called, application/json is passed.

header The header parameter of the Map false request needs to be in key-value pair format.

2.2.6.3 Example

public static void main(String[] args) {

ArtemisConfig artemisConfig = new ArtemisConfig();

artemisConfig.setHost("10.0.0.1:443"); //Platform (nginx) IP and port

artemisConfig.setAppKey("11111111"); //Partner key

artemisConfig.setAppSecret("AAAAAAAAAAAA");//Partner Secret

final String getSecurityApi = "/artemis" + "/api/hello/v1/headget"; // interface path

Map<String, String> path = new HashMap<String, String>(2) {

put(“https://”, getSecurityApi);

};

Map<String, String> head = new HashMap<String, String>(2) { //header parameter of post request

put(“headpost”, “sky-test”);

};

JSONObject jsonBody = new JSONObject();

jsonBody.put(“deviceCodes”,”-1”);

jsonBody.put(“sex”,-1);

jsonBody.put("beginDate",,"2017-09-01 12:00:00");

jsonBody.put(“endDate”,”2017-09-12 12:00:00”);

String body = jsonBody.toJSONString();

String result = ArtemisHttpUtil.doPostStringArtemis(artemisConfig, path, body, null,

null,”application/json”,head);

System.out.println(result);

2.2.7 doPostStringImgArtem

The package uses POST to download the image interface request, and the request body is a json string.
Machine Translated by Google

2.2.7.1 Method Signature

public static HttpResponse doPostStringImgArtemis(ArtemisConfig artemisConfig, Map<String,

String> path, String body,

Map<String, String> querys, String accept, String contentType, Map<String, String> header);

2.2.7.2 Parameter meaning

parameter data whether describe

name type Required

artemisConfi Object true Request host, partner ak/sk package class, format refer to 2.1.3.4

g artemisConfig parameter description

path The path requested by Map true, the format is as described in 2.1.3.1 path parameter description.

body String false A request parameter in JSON format, which needs to be converted to a string.

querys Map false The query parameter of the request url, the format refers to the description of 2.1.3.2 query parameter.

accept String false specifies the data type that the client can receive, the default setting when this parameter is empty

Receive all types.

contentType String false The media type of the request entity body, this parameter is set to the default value when empty

application/text, when this method is called, application/json is passed.

header The header parameter of the Map false request needs to be in key-value pair format.

2.2.7.3 Example

public static void main(String[] args) {

ArtemisConfig artemisConfig = new ArtemisConfig();

artemisConfig.setHost("10.0.0.1:443"); //Platform (nginx) IP and port

artemisConfig.setAppKey("11111111"); //Partner key

artemisConfig.setAppSecret("AAAAAAAAAAAA");//Partner Secret

final String VechicleDataApi = ARTEMIS_PATH +”/api/acs/v1/event/pictures”;

Map<String,String> path = new HashMap<String,String>(2){

put(“https://”,VehicleDataApi);

}
Machine Translated by Google

};

JSONObject jsonBody = new JSONObject();

jsonBody.put(“svrIndexCode”, “30a80833-9ced-46c0-bf53-441a6121856e”);

jsonBody.put(“picUri”, “/pic?6ddz4a-=s72eb2*=ids1*=idp3*=ef8bi12i73=”);

String body = jsonBody.toJSONString();

System.out.println(“body: “+body);

HttpResponse result =ArtemisHttpUtil.doPostStringImgArtemis(artemisConfig,

path,body,null,null,”application/json”,null);

2.2.7 doPostFileFormArtemis

Encapsulates a request using the POST file upload interface. The request is in the form format. This request is only applicable to

Interface with file upload type, please use doPostFormArtemis for other form requests.

2.2.7.1 Method Signature

public static HttpResponse doPostStringImgArtemis(ArtemisConfig artemisConfig, Map<String,

String> path, String body,

Map<String, String> querys, String accept, String contentType, Map<String, String> header);

2.2.7.2 Parameter meaning

parameter data whether describe

name type Required

artemisConfi Object true Request host, partner ak/sk package class, format refer to 2.1.3.4

g artemisConfig parameter description

path The path requested by Map true, the format is as described in 2.1.3.1 path parameter description.

paramMap Map false form The parameter of the form request, which needs to be set in key-value pair format.

querys Map false The query parameter of the request url, the format refers to the description of 2.1.3.2 query parameter.

accept String false specifies the data type that the client can receive, the default setting when this parameter is empty

Receive all types.

contentType String false The media type of the request entity body, this parameter is set to the default value when empty
Machine Translated by Google

application/textÿ

2.2.7.3 Example

public static void main(String[] args) {

ArtemisConfig artemisConfig = new ArtemisConfig();

artemisConfig.setHost("10.0.0.1:443"); //Platform (nginx) IP and port

artemisConfig.setAppKey("11111111"); //Partner key

artemisConfig.setAppSecret("AAAAAAAAAAAAA");//Partner Secret

final String VechicleDataApi = ARTEMIS_PATH +”/api/acs/v1/event/pictures”;

Map<String,String> path = new HashMap<String,String>(2){

put(“https://”,VehicleDataApi);

};

JSONObject jsonBody = new JSONObject();

jsonBody.put(“svrIndexCode”, “30a80833-9ced-46c0-bf53-441a6121856e”);

jsonBody.put(“picUri”, “/pic?6ddz4a-=s72eb2*=ids1*=idp3*=ef8bi12i73=”);

String body = jsonBody.toJSONString();

System.out.println(“body: “+body);

HttpResponse result =ArtemisHttpUtil.doPostStringImgArtemis(artemisConfig,

path,body,null,null,”application/json”,null);

3 Frequently Asked Questions

3.1 Request to get picture interface

When requesting to get the picture interface, and the interface returns in 302 mode, you need to call
doStringImgArtemis interface, this interface will return HttpResponse, users can get
Get the Location of the request header. For specific code, please refer to: ArtemisPostTest.java(artemis
sdk-demo\src\main\java\ga)
Machine Translated by Google

4 Revision History

Serial number change time version change person approver change description

1 2019-09-24 V1.1.2 Zhang Xiaofang 14 Zhang Sen 5 Create a new document to provide basic interface instructions

2 2020-01-13 V1.1.3 Zhang Xiaofang 14 Zhang Sen 5 Modification and update instructions

3 2021-12-14 V1.1.4 Li Chao39 Chen Zhe8 Modification and update instructions

4 2022-05-11 V1.1.5 Huang Jingru Chen Zhe 8 Modification and update instructions

5 2022-06-10 V1.1.6 Li Chao39 Chen Zhe8 Added file upload interface calling API, repaired

Change the update instructions

6 2022-07-27 V1.1.7 Li Chao39 Chen Zhe8 Fixed a large number of CLOSE_WAIT connections

answer questions

You might also like