package cn.exrick.xboot.your.util;
|
|
import java.math.BigDecimal;
|
import java.util.*;
|
|
import cn.exrick.xboot.your.vo.FindHistoryGpsRequest;
|
import cn.exrick.xboot.your.vo.PlaybackURLsVo;
|
import cn.exrick.xboot.your.vo.PreviewURLsVo;
|
import cn.exrick.xboot.your.vo.TalkURLsVo;
|
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.json.JSONUtil;
|
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 org.springframework.stereotype.Component;
|
|
|
/**
|
* 海康车机接口
|
*/
|
@Component
|
public class HaiKangPost {
|
/**
|
* STEP1:设置平台参数,根据实际情况,设置host appkey appsecret 三个参数.
|
*/
|
/**
|
* STEP2:设置OpenAPI接口的上下文
|
*/
|
private static final String ARTEMIS_PATH = "/artemis";
|
private static final String HOST = "111.63.178.115:1443";
|
private static final String APP_KEY = "28156526";
|
private static final String APP_SECRET = "MNkyjHuids4XxFONSOaL";
|
|
//根据车辆编号及时段获取历史定位信息
|
public String findHistoryGps(FindHistoryGpsRequest findHistoryGpsRequest){
|
String findHistoryGpsDataApi = ARTEMIS_PATH +"/api/rtsm/v1/gps/findHistoryGps";
|
Map<String,String> path = new HashMap<String,String>(2){
|
{
|
put("https://",findHistoryGpsDataApi);
|
}
|
};
|
String body= JSONUtil.toJsonStr(findHistoryGpsRequest);
|
String result = doPostStringArtemis(path,body,null,null,"application/json");
|
return result;
|
}
|
|
//查询指定车辆编号的最新定位
|
public String findLatestGps(String[] code){
|
String findHistoryGpsDataApi = ARTEMIS_PATH +"/api/rtsm/v1/gps/findLatestGps";
|
Map<String,String> path = new HashMap<String,String>(2){
|
{
|
put("https://",findHistoryGpsDataApi);
|
}
|
};
|
String body= JSONUtil.toJsonStr(code);
|
String result = doPostStringArtemis(path,body,null,null,"application/json");
|
return result;
|
}
|
|
//获取监控点预览取流URL
|
public String previewURLs(PreviewURLsVo previewURLsVo){
|
String findHistoryGpsDataApi = ARTEMIS_PATH +"/api/video/v1/cameras/previewURLs";
|
Map<String,String> path = new HashMap<String,String>(2){
|
{
|
put("https://",findHistoryGpsDataApi);
|
}
|
};
|
String body= JSONUtil.toJsonStr(previewURLsVo);
|
String result = doPostStringArtemis(path,body,null,null,"application/json");
|
return result;
|
}
|
|
//获取监控点回放取流URL
|
public String playbackURLs(PlaybackURLsVo playbackURLsVo){
|
String findHistoryGpsDataApi = ARTEMIS_PATH +"/api/video/v1/cameras/playbackURLs";
|
Map<String,String> path = new HashMap<String,String>(2){
|
{
|
put("https://",findHistoryGpsDataApi);
|
}
|
};
|
String body= JSONUtil.toJsonStr(playbackURLsVo);
|
String result = doPostStringArtemis(path,body,null,null,"application/json");
|
return result;
|
}
|
|
//语音对讲
|
public String talkURLs(TalkURLsVo talkURLsVo){
|
String findHistoryGpsDataApi = ARTEMIS_PATH +"/api/video/v1/cameras/talkURLs";
|
Map<String,String> path = new HashMap<String,String>(2){
|
{
|
put("https://",findHistoryGpsDataApi);
|
}
|
};
|
String body= JSONUtil.toJsonStr(talkURLsVo);
|
String result = doPostStringArtemis(path,body,null,null,"application/json");
|
return result;
|
}
|
|
//按事件类型获取事件订阅信息
|
public String getTopicInfo(){
|
String findHistoryGpsDataApi = ARTEMIS_PATH +"/api/common/v1/event/getTopicInfo";
|
Map<String,String> path = new HashMap<String,String>(2){
|
{
|
put("https://",findHistoryGpsDataApi);
|
}
|
};
|
BigDecimal eventTypes[] = {new BigDecimal(new String("5201154049"))};
|
Map<String,Object> map = new HashMap<>();
|
map.put("eventTypes",eventTypes);
|
String body= JSONUtil.toJsonStr(map);
|
System.out.println(body);
|
String result = doPostStringArtemis(path,body,null,null,"application/json");
|
return result;
|
}
|
|
public String doPostStringArtemis(Map<String, String> path, String body, Map<String, String> querys, String accept, String contentType) {
|
String httpSchema = (String)path.keySet().toArray()[0];
|
if (httpSchema != null && !StrUtil.isEmpty(httpSchema)) {
|
String responseStr = null;
|
|
try {
|
Map<String, String> headers = new HashMap();
|
if (StrUtil.isNotBlank(accept)) {
|
headers.put("Accept", accept);
|
} else {
|
headers.put("Accept", "*/*");
|
}
|
|
if (StrUtil.isNotBlank(contentType)) {
|
headers.put("Content-Type", contentType);
|
} else {
|
headers.put("Content-Type", "application/text;charset=UTF-8");
|
}
|
|
Request request = new Request(Method.POST_STRING, httpSchema + HOST, (String)path.get(httpSchema), APP_KEY, APP_SECRET, Constants.DEFAULT_TIMEOUT);
|
request.setHeaders(headers);
|
request.setQuerys(querys);
|
request.setStringBody(body);
|
Response response = Client.execute(request);
|
responseStr = getResponseResult2(response);
|
} catch (Exception var10) {
|
}
|
|
return responseStr;
|
} else {
|
throw new RuntimeException("http和https参数错误httpSchema: " + httpSchema);
|
}
|
}
|
|
private String getResponseResult2(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;
|
}
|
|
|
public static void main(String[] args) {
|
HaiKangPost haiKangPost = new HaiKangPost();
|
haiKangPost.getTopicInfo();
|
|
// FindHistoryGpsRequest findHistoryGpsRequest = new FindHistoryGpsRequest();
|
// findHistoryGpsRequest.setVehicleIndexCode("b279d865eabe497db465eb2f4d2cc87d");
|
// findHistoryGpsRequest.setPageNo(1);
|
// findHistoryGpsRequest.setPageSize(20);
|
// findHistoryGpsRequest.setBeginTime("2021-11-25T03:10:01.000+08:00");
|
// findHistoryGpsRequest.setEndTime("2021-11-25T12:10:01.000+08:00");
|
// HaiKangPost haiKangPost = new HaiKangPost();
|
// System.out.println(haiKangPost.findHistoryGps(findHistoryGpsRequest));
|
|
// String code[] = {"b279d865eabe497db465eb2f4d2cc87d"};
|
// System.out.println(findLatestGps(code));
|
|
// PreviewURLsVo previewURLsVo = new PreviewURLsVo();
|
// previewURLsVo.setCameraIndexCode("b279d865eabe497db465eb2f4d2cc87d");
|
// previewURLs(previewURLsVo);
|
}
|
}
|