feat(sdk): 新增华为盒子接口及服务
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
- 新增 HuaWeiBoxApi 接口定义 - 实现 HuaWeiBoxApiService 类提供服务 - 增加 HuaWeiHttp 工具类处理 HTTP 请求
This commit is contained in:
parent
21c149bf0c
commit
3b27487b3c
@ -0,0 +1,20 @@
|
|||||||
|
package org.dromara.sis.sdk.huawei;
|
||||||
|
|
||||||
|
import org.dromara.sis.sdk.huawei.domain.AddLibReq;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lsm
|
||||||
|
* @apiNote HuaWeiBoxApi
|
||||||
|
* @since 2025/7/9
|
||||||
|
*/
|
||||||
|
public interface HuaWeiBoxApi {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增目标名单库
|
||||||
|
*
|
||||||
|
* @param req 入参
|
||||||
|
* @return Integer
|
||||||
|
*/
|
||||||
|
Integer addPersonLib(AddLibReq req);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
package org.dromara.sis.sdk.huawei.domain;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lsm
|
||||||
|
* @apiNote AddLibReq
|
||||||
|
* @since 2025/7/9
|
||||||
|
*/
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class AddLibReq {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 目标库类型
|
||||||
|
* 2:目标库黑名单3:目标库白名单 4: 目标库红名单
|
||||||
|
*/
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 目标库名称
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 目标库描述
|
||||||
|
*/
|
||||||
|
private String description;
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
package org.dromara.sis.sdk.huawei.service;
|
||||||
|
|
||||||
|
import cn.hutool.http.HttpResponse;
|
||||||
|
import cn.hutool.json.JSONObject;
|
||||||
|
import cn.hutool.json.JSONUtil;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.dromara.sis.sdk.huawei.HuaWeiBoxApi;
|
||||||
|
import org.dromara.sis.sdk.huawei.domain.AddLibReq;
|
||||||
|
import org.dromara.sis.sdk.huawei.utils.HuaWeiHttp;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lsm
|
||||||
|
* @apiNote HuaWeiBoxApiService
|
||||||
|
* @since 2025/7/9
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class HuaWeiBoxApiService implements HuaWeiBoxApi {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private HuaWeiHttp huaWeiHttp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增目标名单库
|
||||||
|
*
|
||||||
|
* @param req 入参
|
||||||
|
* @return Integer
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Integer addPersonLib(AddLibReq req) {
|
||||||
|
String url = "/sdk_service/rest/facerepositories";
|
||||||
|
|
||||||
|
JSONObject json = JSONUtil.parseObj(req);
|
||||||
|
|
||||||
|
String jsonStr = huaWeiHttp.doPost(url, json.toString());
|
||||||
|
|
||||||
|
if (jsonStr == null) {
|
||||||
|
log.error("新增目标名单库失败");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
JSONObject obj = JSONUtil.parseObj(jsonStr);
|
||||||
|
return obj.getInt("groupid");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,74 @@
|
|||||||
|
package org.dromara.sis.sdk.huawei.utils;
|
||||||
|
|
||||||
|
import cn.hutool.http.HttpRequest;
|
||||||
|
import cn.hutool.http.HttpResponse;
|
||||||
|
import cn.hutool.json.JSONObject;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.dromara.common.redis.utils.RedisUtils;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lsm
|
||||||
|
* @apiNote HuaWeiHttp
|
||||||
|
* @since 2025/7/7
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class HuaWeiHttp {
|
||||||
|
|
||||||
|
private static final String BASE_URL = "https://192.168.110.195:18531";
|
||||||
|
private static final String USERNAME = "huawei";
|
||||||
|
private static final String PASSWORD = "qweasd123";
|
||||||
|
|
||||||
|
// 每次调用请求需要登录,获取JSESSIONID
|
||||||
|
public Boolean login() {
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
json.putOnce("userName", USERNAME);
|
||||||
|
json.putOnce("password", PASSWORD);
|
||||||
|
json.putOnce("timeout", 1800);
|
||||||
|
|
||||||
|
String url = BASE_URL + "/loginInfo/login/v1.0";
|
||||||
|
String jsonStr = json.toString();
|
||||||
|
// 发送请求获取响应
|
||||||
|
// 使用 try-with-resources 确保资源释放
|
||||||
|
try (HttpResponse response = HttpRequest.post(url)
|
||||||
|
.header("Content-Type", "application/json")
|
||||||
|
.header("Cache-Control", "no-cache")
|
||||||
|
.body(jsonStr)
|
||||||
|
.execute()) {
|
||||||
|
if (response.getStatus() == 200 && response.getCookie("JSESSIONID") != null) {
|
||||||
|
RedisUtils.setCacheObject("JSESSIONID", response.getCookie("JSESSIONID").toString());
|
||||||
|
RedisUtils.expire("JSESSIONID", 1800);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
log.error("华为盒子登录失败,msg:{}", response.body());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String doPost(String url, String json) {
|
||||||
|
if (!RedisUtils.isExistsObject("JSESSIONID")) {
|
||||||
|
if (!this.login()) {
|
||||||
|
RedisUtils.deleteObject("JSESSIONID");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String api = BASE_URL + url;
|
||||||
|
|
||||||
|
try (HttpResponse response = HttpRequest.post(api)
|
||||||
|
.header("Content-Type", "application/json")
|
||||||
|
.header("Cache-Control", "no-cache")
|
||||||
|
.header("Cookie", RedisUtils.getCacheObject("JSESSIONID"))
|
||||||
|
.body(json)
|
||||||
|
.execute()) {
|
||||||
|
if (response.isOk()) {
|
||||||
|
return response.body();
|
||||||
|
} else {
|
||||||
|
log.error("请求失败,msg:{}", response.body());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user