package com.ycl.service;
|
|
import com.alibaba.fastjson2.JSON;
|
import com.alibaba.fastjson2.JSONObject;
|
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
|
import com.hikvision.artemis.sdk.config.ArtemisConfig;
|
import com.ycl.config.HKProperties;
|
import com.ycl.domain.form.CameraCommandForm;
|
import com.ycl.domain.query.CameraPlayQuery;
|
import com.ycl.domain.query.CameraQuery;
|
import com.ycl.domain.result.HKResult;
|
import org.springframework.stereotype.Service;
|
import org.springframework.util.StringUtils;
|
|
import java.util.*;
|
|
/**
|
* @author:xp
|
* @date:2024/12/20 10:57
|
*/
|
@Service
|
public class HKService {
|
|
private final HKProperties hkProperties;
|
|
public HKService(HKProperties hkProperties) {
|
this.hkProperties = hkProperties;
|
}
|
|
/**
|
* 获取监控资源点-摄像头
|
* @see <a href="https://open.hikvision.com/docs/docId?productId=5c67f1e2f05948198c909700&version=%2Ff95e951cefc54578b523d1738f65f0a1&tagPath=API%E5%88%97%E8%A1%A8-%E8%A7%86%E9%A2%91%E5%BA%94%E7%94%A8%E6%9C%8D%E5%8A%A1-%E8%A7%86%E9%A2%91%E8%B5%84%E6%BA%90#a11a856d">...</a>
|
*
|
*/
|
public Map<String,Object> getCamerasPage(CameraQuery query) {
|
/**
|
* STEP1:设置平台参数,根据实际情况,设置host appkey appsecret 三个参数.
|
*/
|
ArtemisConfig.host = hkProperties.getHost(); // 平台的ip端口
|
ArtemisConfig.appKey = hkProperties.getAk(); // 密钥appkey
|
ArtemisConfig.appSecret = hkProperties.getSk();// 密钥appSecret
|
|
/**
|
* STEP2:设置OpenAPI接口的上下文
|
*/
|
final String ARTEMIS_PATH = "/artemis";
|
|
/**
|
* STEP3:设置接口的URI地址
|
*/
|
final String previewURLsApi = ARTEMIS_PATH + "/api/resource/v2/camera/search";
|
Map<String, String> path = new HashMap<String, String>(2) {
|
{
|
put("https://", previewURLsApi);//根据现场环境部署确认是http还是https
|
}
|
};
|
|
/**
|
* STEP4:设置参数提交方式
|
*/
|
String contentType = "application/json";
|
|
/**
|
* STEP5:组装请求参数
|
*/
|
JSONObject jsonBody = new JSONObject();
|
jsonBody.put("pageNo", query.getPageNo());
|
jsonBody.put("pageSize", query.getPageSize());
|
jsonBody.put("orderBy", "name");
|
jsonBody.put("orderType", "desc");
|
|
if (StringUtils.hasText(query.getName())) {
|
// 查询条件
|
List<Map> expressions = new ArrayList<>(1);
|
Map<String, Object> nameSearch = new HashMap<>(3);
|
nameSearch.put("key", "name");
|
nameSearch.put("operator", 6);
|
nameSearch.put("values", Arrays.asList(query.getName()));
|
expressions.add(nameSearch);
|
|
jsonBody.put("expressions", expressions);
|
}
|
|
String body = jsonBody.toJSONString();
|
/**
|
* STEP6:调用接口
|
*/
|
String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType , null);// post请求application/json类型参数
|
HKResult hkResult = JSON.parseObject(result, HKResult.class);
|
return hkResult.getData();
|
}
|
|
|
/**
|
* 获取视频流地址
|
*
|
* @see <a href="https://open.hikvision.com/docs/docId?productId=5c67f1e2f05948198c909700&version=%2Ff95e951cefc54578b523d1738f65f0a1&tagPath=API%E5%88%97%E8%A1%A8-%E8%A7%86%E9%A2%91%E5%BA%94%E7%94%A8%E6%9C%8D%E5%8A%A1-%E8%A7%86%E9%A2%91%E8%83%BD%E5%8A%9B#b5bd6fd9">...</a>
|
* @param query
|
* @return
|
*/
|
public Map<String, Object> previewURLs(CameraPlayQuery query) {
|
/**
|
* STEP1:设置平台参数,根据实际情况,设置host appkey appsecret 三个参数.
|
*/
|
ArtemisConfig.host = hkProperties.getHost(); // 平台的ip端口
|
ArtemisConfig.appKey = hkProperties.getAk(); // 密钥appkey
|
ArtemisConfig.appSecret = hkProperties.getSk();// 密钥appSecret
|
|
/**
|
* STEP2:设置OpenAPI接口的上下文
|
*/
|
final String ARTEMIS_PATH = "/artemis";
|
|
/**
|
* STEP3:设置接口的URI地址
|
*/
|
final String previewURLsApi = ARTEMIS_PATH + "/api/video/v2/cameras/previewURLs";
|
Map<String, String> path = new HashMap<String, String>(2) {
|
{
|
put("https://", previewURLsApi);//根据现场环境部署确认是http还是https
|
}
|
};
|
|
/**
|
* STEP4:设置参数提交方式
|
*/
|
String contentType = "application/json";
|
|
/**
|
* STEP5:组装请求参数
|
*/
|
JSONObject jsonBody = new JSONObject();
|
jsonBody.put("cameraIndexCode", query.getIndexCode());
|
jsonBody.put("protocol", query.getProtocol());
|
// jsonBody.put("netZoneCode", 53);
|
|
|
String body = jsonBody.toJSONString();
|
/**
|
* STEP6:调用接口
|
*/
|
String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType , null);// post请求application/json类型参数
|
HKResult hkResult = JSON.parseObject(result, HKResult.class);
|
return hkResult.getData();
|
}
|
|
|
/**
|
* 控制摄像头
|
*
|
* @see <a href="https://open.hikvision.com/docs/docId?productId=5c67f1e2f05948198c909700&version=%2Ff95e951cefc54578b523d1738f65f0a1&tagPath=API%E5%88%97%E8%A1%A8-%E8%A7%86%E9%A2%91%E5%BA%94%E7%94%A8%E6%9C%8D%E5%8A%A1-%E8%A7%86%E9%A2%91%E8%83%BD%E5%8A%9B#e6643a97">...</a>
|
* @param form
|
* @return
|
*/
|
public Boolean controlling(CameraCommandForm form) {
|
/**
|
* STEP1:设置平台参数,根据实际情况,设置host appkey appsecret 三个参数.
|
*/
|
ArtemisConfig.host = hkProperties.getHost(); // 平台的ip端口
|
ArtemisConfig.appKey = hkProperties.getAk(); // 密钥appkey
|
ArtemisConfig.appSecret = hkProperties.getSk();// 密钥appSecret
|
|
/**
|
* STEP2:设置OpenAPI接口的上下文
|
*/
|
final String ARTEMIS_PATH = "/artemis";
|
|
/**
|
* STEP3:设置接口的URI地址
|
*/
|
final String controllerApi = ARTEMIS_PATH + "/api/video/v1/ptzs/controlling";
|
Map<String, String> path = new HashMap<String, String>(2) {
|
{
|
put("https://", controllerApi);//根据现场环境部署确认是http还是https
|
}
|
};
|
|
/**
|
* STEP4:设置参数提交方式
|
*/
|
String contentType = "application/json";
|
|
/**
|
* STEP5:组装请求参数
|
*/
|
JSONObject jsonBody = new JSONObject();
|
jsonBody.put("cameraIndexCode", form.getIndexCode());
|
jsonBody.put("action", form.getAction());
|
jsonBody.put("command", form.getCommand());
|
|
|
String body = jsonBody.toJSONString();
|
/**
|
* STEP6:调用接口
|
*/
|
String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType , null);// post请求application/json类型参数
|
HKResult hkResult = JSON.parseObject(result, HKResult.class);
|
return "success".equals(hkResult.getMsg());
|
}
|
}
|