51 lines
1.8 KiB
Java
51 lines
1.8 KiB
Java
|
|
package com.zhgd.xmgl.util;
|
||
|
|
|
||
|
|
import com.hikvision.artemis.sdk.Client;
|
||
|
|
import com.hikvision.artemis.sdk.Request;
|
||
|
|
import com.hikvision.artemis.sdk.Response;
|
||
|
|
import com.hikvision.artemis.sdk.constant.Constants;
|
||
|
|
import com.hikvision.artemis.sdk.enums.Method;
|
||
|
|
import lombok.extern.slf4j.Slf4j;
|
||
|
|
|
||
|
|
import java.util.HashMap;
|
||
|
|
import java.util.Map;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 海康接口
|
||
|
|
*/
|
||
|
|
@Slf4j
|
||
|
|
public class HikvisionUtil {
|
||
|
|
public static String doPost(String host, String path, String body, Map<String, String> querys, String appKey, String appSecret) {
|
||
|
|
log.info("HikvisionUtil#doPost.url:{}", host + path);
|
||
|
|
String responseStr = null;
|
||
|
|
try {
|
||
|
|
Map<String, String> headers = new HashMap();
|
||
|
|
headers.put("Accept", "*/*");
|
||
|
|
headers.put("Content-Type", "application/json");
|
||
|
|
Request request = new Request(Method.POST_STRING, host, path, appKey, appSecret, Constants.DEFAULT_TIMEOUT);
|
||
|
|
request.setHeaders(headers);
|
||
|
|
request.setQuerys(querys);
|
||
|
|
request.setStringBody(body);
|
||
|
|
Response response = Client.execute(request);
|
||
|
|
responseStr = getResponseResult(response);
|
||
|
|
log.info("HikvisionUtil#doPost.getResponseResult:{}", responseStr);
|
||
|
|
} catch (Exception var10) {
|
||
|
|
var10.printStackTrace();
|
||
|
|
}
|
||
|
|
return responseStr;
|
||
|
|
}
|
||
|
|
|
||
|
|
private static String getResponseResult(Response response) {
|
||
|
|
String responseStr = null;
|
||
|
|
int statusCode = response.getStatusCode();
|
||
|
|
if (!String.valueOf(statusCode).startsWith("2") && !String.valueOf(statusCode).startsWith("3")) {
|
||
|
|
//String msg = response.getErrorMessage();
|
||
|
|
responseStr = response.getBody();
|
||
|
|
} else {
|
||
|
|
responseStr = response.getBody();
|
||
|
|
}
|
||
|
|
|
||
|
|
return responseStr;
|
||
|
|
}
|
||
|
|
}
|