185 lines
6.9 KiB
Java
185 lines
6.9 KiB
Java
|
|
package com.zhgd.xmgl.call;
|
|||
|
|
|
|||
|
|
import com.alibaba.fastjson.JSONObject;
|
|||
|
|
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
|
|||
|
|
import com.hikvision.artemis.sdk.config.ArtemisConfig;
|
|||
|
|
import com.zhgd.xmgl.modules.worker.entity.WorkerInfo;
|
|||
|
|
import com.zhgd.xmgl.util.Base64Util;
|
|||
|
|
import com.zhgd.xmgl.util.HikvisionUtil;
|
|||
|
|
import com.zhgd.xmgl.util.PathUtil;
|
|||
|
|
import lombok.extern.slf4j.Slf4j;
|
|||
|
|
import org.springframework.beans.factory.annotation.Value;
|
|||
|
|
import org.springframework.stereotype.Component;
|
|||
|
|
|
|||
|
|
import java.util.ArrayList;
|
|||
|
|
import java.util.HashMap;
|
|||
|
|
import java.util.Map;
|
|||
|
|
|
|||
|
|
@Slf4j
|
|||
|
|
@Component
|
|||
|
|
public class HikvisionCall {
|
|||
|
|
@Value("${upload.image.url.prefix:}")
|
|||
|
|
private String imageUrlPrefix;
|
|||
|
|
|
|||
|
|
public static String GetCameraPreviewURL() {
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* STEP1:设置平台参数,根据实际情况,设置host appkey appsecret 三个参数.
|
|||
|
|
*/
|
|||
|
|
ArtemisConfig.host = "127.0.0.1:443"; // 平台的ip端口
|
|||
|
|
ArtemisConfig.appKey = "29180881"; // 密钥appkey
|
|||
|
|
ArtemisConfig.appSecret = "XO0wCAYGi4KV70ybjznx";// 密钥appSecret
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* STEP2:设置OpenAPI接口的上下文
|
|||
|
|
*/
|
|||
|
|
final String ARTEMIS_PATH = "/artemis";
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* STEP3:设置接口的URI地址
|
|||
|
|
*/
|
|||
|
|
final String previewURLsApi = ARTEMIS_PATH + "/api/video/v1/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", "748d84750e3a4a5bbad3cd4af9ed5101");
|
|||
|
|
jsonBody.put("streamType", 0);
|
|||
|
|
jsonBody.put("protocol", "rtsp");
|
|||
|
|
jsonBody.put("transmode", 1);
|
|||
|
|
jsonBody.put("expand", "streamform=ps");
|
|||
|
|
String body = jsonBody.toJSONString();
|
|||
|
|
/**
|
|||
|
|
* STEP6:调用接口
|
|||
|
|
*/
|
|||
|
|
String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null);// post请求application/json类型参数
|
|||
|
|
return result;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void addWorkerForHikvision(WorkerInfo workerInfo) {
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* STEP1:设置平台参数,根据实际情况,设置host appkey appsecret 三个参数.
|
|||
|
|
*/
|
|||
|
|
ArtemisConfig.host = "127.0.0.1:443"; // 平台的ip端口
|
|||
|
|
ArtemisConfig.appKey = "29180881"; // 密钥appkey
|
|||
|
|
ArtemisConfig.appSecret = "XO0wCAYGi4KV70ybjznx";// 密钥appSecret
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* STEP2:设置OpenAPI接口的上下文
|
|||
|
|
*/
|
|||
|
|
final String ARTEMIS_PATH = "/artemis";
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* STEP3:设置接口的URI地址
|
|||
|
|
*/
|
|||
|
|
final String previewURLsApi = ARTEMIS_PATH + "/api/resource/v2/person/single/add";
|
|||
|
|
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("personId", workerInfo.getId());
|
|||
|
|
jsonBody.put("personName", workerInfo.getWorkerName());
|
|||
|
|
jsonBody.put("gender", workerInfo.getSex());
|
|||
|
|
jsonBody.put("orgIndexCode", "todo");//todo
|
|||
|
|
jsonBody.put("birthday", workerInfo.getBirthday());
|
|||
|
|
jsonBody.put("phoneNo", workerInfo.getPhoneNumber());
|
|||
|
|
jsonBody.put("email", workerInfo.getPersonMail());
|
|||
|
|
jsonBody.put("certificateType", "111");
|
|||
|
|
jsonBody.put("certificateNo", workerInfo.getIdCard());
|
|||
|
|
jsonBody.put("jobNo", workerInfo.getPersonSn());
|
|||
|
|
ArrayList<HashMap<String, String>> faceList = new ArrayList<>();
|
|||
|
|
HashMap<String, String> faceMap = new HashMap<>();
|
|||
|
|
faceMap.put("faceData", Base64Util.convertFileToBase64(PathUtil.reviseSlash(imageUrlPrefix + "/" + workerInfo.getFieldAcquisitionUrl())));
|
|||
|
|
faceList.add(faceMap);
|
|||
|
|
jsonBody.put("faces", faceList);
|
|||
|
|
String body = jsonBody.toJSONString();
|
|||
|
|
/**
|
|||
|
|
* STEP6:调用接口
|
|||
|
|
*/
|
|||
|
|
String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null);// post请求application/json类型参数
|
|||
|
|
log.info("海康rs:{}", result);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void editWorkerForHikvision(WorkerInfo workerInfo) {
|
|||
|
|
/**
|
|||
|
|
* STEP1:设置平台参数,根据实际情况,设置host appkey appsecret 三个参数.
|
|||
|
|
*/
|
|||
|
|
ArtemisConfig.host = "127.0.0.1:443"; // 平台的ip端口
|
|||
|
|
ArtemisConfig.appKey = "29180881"; // 密钥appkey
|
|||
|
|
ArtemisConfig.appSecret = "XO0wCAYGi4KV70ybjznx";// 密钥appSecret
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* STEP2:设置OpenAPI接口的上下文
|
|||
|
|
*/
|
|||
|
|
final String ARTEMIS_PATH = "/artemis";
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* STEP3:设置接口的URI地址
|
|||
|
|
*/
|
|||
|
|
final String previewURLsApi = ARTEMIS_PATH + "/api/resource/v1/person/single/update";
|
|||
|
|
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("personId", workerInfo.getId());
|
|||
|
|
jsonBody.put("personName", workerInfo.getWorkerName());
|
|||
|
|
jsonBody.put("gender", workerInfo.getSex());
|
|||
|
|
jsonBody.put("orgIndexCode", "todo");//todo
|
|||
|
|
jsonBody.put("birthday", workerInfo.getBirthday());
|
|||
|
|
jsonBody.put("phoneNo", workerInfo.getPhoneNumber());
|
|||
|
|
jsonBody.put("email", workerInfo.getPersonMail());
|
|||
|
|
jsonBody.put("certificateType", "111");
|
|||
|
|
jsonBody.put("certificateNo", workerInfo.getIdCard());
|
|||
|
|
jsonBody.put("jobNo", workerInfo.getPersonSn());
|
|||
|
|
ArrayList<HashMap<String, String>> faceList = new ArrayList<>();
|
|||
|
|
HashMap<String, String> faceMap = new HashMap<>();
|
|||
|
|
faceMap.put("faceData", Base64Util.convertFileToBase64(PathUtil.reviseSlash(imageUrlPrefix + "/" + workerInfo.getFieldAcquisitionUrl())));
|
|||
|
|
faceList.add(faceMap);
|
|||
|
|
jsonBody.put("faces", faceList);
|
|||
|
|
String body = jsonBody.toJSONString();
|
|||
|
|
/**
|
|||
|
|
* STEP6:调用接口
|
|||
|
|
*/
|
|||
|
|
String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null);// post请求application/json类型参数
|
|||
|
|
//HikvisionUtil.doPost("https://"+previewURLsApi,)
|
|||
|
|
log.info("海康rs:{}", result);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
}
|