海康ISAPI删除用户信息
IotIsapiUrlConstant
/**
* 海康ISAPI请求URL
*
* @date 2022/10/12
*/
public class IotIsapiUrlConstant {
/**
* 添加人员信息
* post
*/
public static final String ADD_USER_INFO = "/ISAPI/AccessControl/UserInfo/Record?format=json";
/**
* 添加人脸数据
* post
*/
public static final String ADD_USER_FACE = "/ISAPI/Intelligent/FDLib/FaceDataRecord?format=json";
/**
* 修改人脸数据
*/
public static final String EDIT_USER_FACE = "/ISAPI/Intelligent/FDLib/FDModify?format=json";
/**
* 添加或修改人脸数据
* put
*/
public static final String FDSETUP_USER_FACE = "/ISAPI/Intelligent/FDLib/FDSetUp?format=json";
/**
* 添加或修改人员数据
* put
*/
public static final String SETUP_USER_INFO= "/ISAPI/AccessControl/UserInfo/SetUp?format=json";
/**
* 上传人脸照片
*/
public static final String UPLOAD_STORAGE_CLOUD = "/ISAPI/Intelligent/uploadStorageCloud?format=json";
/**
* 删除人员信息
*/
public static final String DEL_USER_INFO = "/ISAPI/AccessControl/UserInfo/Delete?format=json";
/**
* 查询人员信息
*/
public static final String QUER_USER_INFO = "/ISAPI/AccessControl/UserInfo/Search?format=json";
/**
* 修改人员信息
*/
public static final String MODIFY_USER_INFO = "/ISAPI/AccessControl/UserInfo/Modify?format=json";
/**
* 获取人员权限计划模板参数配置能力
*/
public static final String USER_RIGHTPLAN_TEMPLATE = "/ISAPI/AccessControl/UserRightPlanTemplate/capabilities?format=json";
/**
* 人员权限计划模板
* 模板编号,从1开始,设备支持的最大值从能力集中获取
*/
public static String allocationUserRightPlanTemplate(String planTemplateID){
return "/ISAPI/AccessControl/UserRightPlanTemplate/"+planTemplateID+"?format=json";
}
/**
* 员权限周计划
* 周计划编号,从1开始,设备支持的最大值从能力集中获取
* 128
*/
public static String allocationUserRightWeekPlanCfg(int weekPlanID){
return "/ISAPI/AccessControl/UserRightWeekPlanCfg/"+weekPlanID+"?format=json";
}
/**
* 查询人员数量
*/
public static final String GET_USER_COUNT= "/ISAPI/AccessControl/UserInfo/Count?format=json";
}
HttpClientUtil
/**
* @date 2023/11/9
*/
@Slf4j
public class HttpClientUtil {
public static CloseableHttpClient httpUsernamePassword(String username, String password) {
Credentials creds = new UsernamePasswordCredentials(username, password);
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(AuthScope.ANY, creds);
return HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
}
/**
* get 请求
*
* @param username 账号
* @param password 密码
* @param isapiUrl URL
* @return
*/
public static String getHttpIsapi(String username, String password, String isapiUrl) {
HttpGet httpGet = new HttpGet(isapiUrl);
CloseableHttpClient httpclient = httpUsernamePassword(username, password);
try {
HttpResponse response = httpclient.execute(httpGet);
return EntityUtils.toString(response.getEntity(), "utf-8");
} catch (Exception e) {
log.error("调用接口失败", e);
}
return null;
}
/**
* post 请求
*
* @param username 账号
* @param password 密码
* @param isapiUrl URL
* @return
*/
public static String postHttpIsapi(String username, String password, String isapiUrl, String body) {
HttpPost httpPost = new HttpPost(isapiUrl);
CloseableHttpClient httpclient = httpUsernamePassword(username, password);
httpPost.setEntity(new StringEntity(body, "UTF-8"));
try {
HttpResponse response = httpclient.execute(httpPost);
return EntityUtils.toString(response.getEntity(), "utf-8");
} catch (Exception e) {
log.error("调用接口失败", e);
}
return null;
}
/**
* put 请求
*
* @param username 账号
* @param password 密码
* @param isapiUrl URL
* @param putXml 参数 字符串
* @return
*/
public static String putHttpIsapi(String username, String password, String isapiUrl, String putXml) {
HttpPut httpPut = new HttpPut(isapiUrl);
CloseableHttpClient httpclient = httpUsernamePassword(username, password);
httpPut.setEntity(new StringEntity(putXml, "UTF-8"));
try {
HttpResponse response = httpclient.execute(httpPut);
return EntityUtils.toString(response.getEntity(), "utf-8");
} catch (Exception e) {
log.error("调用接口失败", e);
}
return null;
}
public static String doPostModFacePicRecord(String username, String password, String url, String json, byte[] faceimage, String boundary) {
String respoon = "";
try {
CloseableHttpResponse response;
CloseableHttpClient httpsClient = httpUsernamePassword(username, password);
HttpPost method = new HttpPost(url);
method.addHeader("Accept-Language", "zh-CN");
method.addHeader("Content-Type", "multipart/form-data; boundary=" + boundary);
method.addHeader("User-Agent", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)");
method.addHeader("Accept-Encoding", "gzip, deflate");
method.addHeader("Connection", "Keep-Alive");
method.addHeader("Cache-Control", "no-cache");
String bodyParam =
"--" + boundary + "\r\n"
+ "Content-Disposition: form-data; name=\"FaceDataRecord\";\r\n"
+ "Content-Type: text/json\r\n"
+ "Content-Length: " + json.length() + "\r\n\r\n"
+ json + "\r\n"
+ "--" + boundary + "\r\n"
+ "Content-Disposition: form-data; name=\"img\";\r\n"
+ "Content-Type: image/jpeg\r\n"
+ "Content-Length: " + faceimage.length + "\r\n\r\n"
+ faceimage
+ "\r\n--" + boundary + "--\r\n";
HttpEntity inboundInfoEntity = new StringEntity(bodyParam, "UTF-8");
method.setEntity(inboundInfoEntity);
response = httpsClient.execute(method);
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_OK) {
respoon = "error " + statusCode;
}
HttpEntity entity = response.getEntity();
if (entity == null) {
respoon = "error response is null";
}
respoon = EntityUtils.toString(entity, "utf-8");
// Release the connection
method.releaseConnection();
} catch (IOException e) {
log.error("添加人脸失败", e);
}
return respoon;
}
public static String doPutModFacePicRecord(String username, String password, String url, String json, byte[] faceimage, String boundary) {
String respon = "";
try {
CloseableHttpResponse response;
CloseableHttpClient httpsClient = httpUsernamePassword(username, password);
HttpPut method = new HttpPut(url);
method.addHeader("Accept", "text/html, application/xhtml+xml");
method.addHeader("Accept-Language", "zh-CN");
method.addHeader("Content-Type", "multipart/form-data; boundary=" + boundary);
method.addHeader("User-Agent", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)");
method.addHeader("Accept-Encoding", "gzip, deflate");
method.addHeader("Connection", "Keep-Alive");
method.addHeader("Cache-Control", "no-cache");
String bodyParam =
"--" + boundary + "\r\n"
+ "Content-Disposition: form-data; name=\"FaceDataRecord\";\r\n"
+ "Content-Type: text/json\r\n"
+ "Content-Length: " + json.length() + "\r\n\r\n"
+ json + "\r\n"
+ "--" + boundary + "\r\n"
+ "Content-Disposition: form-data; name=\"img\";\r\n"
+ "Content-Type: image/jpeg\r\n"
+ "Content-Length: " + faceimage.length + "\r\n\r\n"
+ faceimage
+ "\r\n--" + boundary + "--\r\n";
HttpEntity inboundInfoEntity = new StringEntity(bodyParam, "UTF-8");
method.setEntity(inboundInfoEntity);
response = httpsClient.execute(method);
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_OK) {
respon = "error " + statusCode;
}
HttpEntity entity = response.getEntity();
if (entity == null) {
respon = "error response is null";
}
respon = EntityUtils.toString(entity, "utf-8");
// Release the connection
method.releaseConnection();
} catch (IOException e) {
log.error("添加人脸失败", e);
}
return respon;
}
}
IotUserInfoDelCond
/**
* req, object, 删除条件
* @date 2023/11/13
*/
@Getter
@Setter
public class IotUserInfoDelCond {
/**opt, string, 操作类型
* byTerminal
* */
private String operateType;
/**
* 工号(人员ID)
* opt, array, 人员ID列表, subType:object,
* desc:EployeeNoList字段不存在或为空时,代表删除所有人员。删除所有人员时,超时时间建议设置为60s。删除人员
* 时,人员关联的凭证信息也会被删除。
*/
private List<IotEmployeeNo> EmployeeNoList;
/**opt, array, 终端ID列表, subType:int, desc:type为byTerminal,byTerminalOrg时必填,终端ID列表(目前仅支持单个终端)*/
private List<Integer> terminalNoList;
}
IotEmployeeNo
/**
* 工号(人员ID)
* @date 2023/11/13
*/
@Getter
@Setter
public class IotEmployeeNo {
/**
* 工号(人员ID)
*/
private String employeeNo;
}
IotDelUserFaceParam
/**
*删除用户人脸信息
* @author czm
* @date 2023/11/10
*/
@Getter
@Setter
public class IotDelUserFaceParam {
private IotUserInfoDelCond UserInfoDelCond;
}
删除用户信息
/**
*camera 设备信息
*userIds 用户编码集合
*/
public static String deleteUserFace(IotCameraParam camera, Collection<Long> userIds) {
String url = HTTP + camera.getIp() + IotIsapiUrlConstant.DEL_USER_INFO;
IotUserInfoDelCond userInfoDelCond = new IotUserInfoDelCond();
userInfoDelCond.setOperateType("byTerminal");
if (CollUtil.isNotEmpty(userIds)) {
List<IotEmployeeNo> employeeNos = new ArrayList<>();
for (Long userId : userIds) {
IotEmployeeNo employeeNo = new IotEmployeeNo();
employeeNo.setEmployeeNo(String.valueOf(userId));
employeeNos.add(employeeNo);
}
userInfoDelCond.setEmployeeNoList(employeeNos);
}
userInfoDelCond.setTerminalNoList(Collections.singletonList(1));
IotDelUserFaceParam delUserFaceParam = new IotDelUserFaceParam();
delUserFaceParam.setUserInfoDelCond(userInfoDelCond);
String delUserInfoRespoon = HttpClientUtil.putHttpIsapi(camera.getUsername(), camera.getPassword(), url, JSONUtil.toJsonStr(delUserFaceParam));
log.info("ISAPI delUser:{}", delUserInfoRespoon);
return delUserInfoRespoon;
}