This commit is contained in:
xx572959496 2025-06-20 10:01:41 +08:00
parent 1ba009cf9e
commit e34403c39c

View File

@ -12,6 +12,7 @@ import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import org.apache.logging.log4j.LogManager;
@ -120,40 +121,43 @@ public class CheckLogin {
String password = encrypt2ToMD5(user.getPassword());
String username = user.getUsername();
log.info("加密密码为:{}", password);
String body = HttpRequest.post("https://login.oa.unionpay.com/idsapi/portal/Login")
.form("username", username)
.form("password", password)
.form("saveUsername", "false")
.form("savePassword", "false")
.form("loginType", "normal")
.form("code", "")
.execute().body();
JSONObject data = JSONUtil.parseObj(body).getJSONObject("data");
if (data != null) {
String token = data.getStr("token");
log.info("认证系统返回token {}", token);
String thirdBody = HttpRequest
.get("http://oms.oa.unionpay.com/prod-api/checkTokenThenLogin?personType=0&token=" + token)
.execute().body();
JSONObject thirdBodyJson = JSONUtil.parseObj(thirdBody);
if (!"200".equals(thirdBodyJson.getStr("code"))) {
log.error("签到系统返回报文出错 {}", thirdBodyJson);
return false;
}
String thirdToken = thirdBodyJson.getStr("localToken");
String resultBody = HttpRequest.post("http://oms.oa.unionpay.com/prod-api/atds/ds/" + signMark)
.header("Authorization", "Bearer " + thirdToken)
.execute().body();
JSONObject signJson = JSONUtil.parseObj(resultBody);
if ("200".equals(signJson.getStr("code"))) {
String signDateTime = DateUtil.formatDateTime(signJson.getDate("data"));
result = true;
log.info("{} 打卡时间 {}", user.getUsername(), signDateTime);
try (HttpResponse response = HttpRequest.post("https://login.oa.unionpay.com/idsapi/portal/Login")
.form("username", username)
.form("password", password)
.form("saveUsername", "false")
.form("savePassword", "false")
.form("loginType", "normal")
.form("code", "")
.execute()) {
JSONObject data = JSONUtil.parseObj(response.body()).getJSONObject("data");
if (data != null) {
String token = data.getStr("token");
log.info("认证系统返回token {}", token);
try (HttpResponse thirdResponse = HttpRequest
.get("http://oms.oa.unionpay.com/prod-api/checkTokenThenLogin?personType=0&token=" + token)
.execute()) {
JSONObject thirdBodyJson = JSONUtil.parseObj(thirdResponse.body());
if (!"200".equals(thirdBodyJson.getStr("code"))) {
log.error("签到系统返回报文出错 {}", thirdBodyJson);
return false;
}
String thirdToken = thirdBodyJson.getStr("localToken");
try (HttpResponse httpResponse = HttpRequest.post("http://oms.oa.unionpay.com/prod-api/atds/ds/" + signMark)
.header("Authorization", "Bearer " + thirdToken)
.execute()) {
JSONObject signJson = JSONUtil.parseObj(httpResponse.body());
if ("200".equals(signJson.getStr("code"))) {
String signDateTime = DateUtil.formatDateTime(signJson.getDate("data"));
result = true;
log.info("{} 打卡时间 {}", user.getUsername(), signDateTime);
} else {
log.error("签到接口出错 {}", signJson);
}
}
}
} else {
log.error("签到接口出错 {}", resultBody);
log.error("认证系统返回报文出错 {}", response.body());
}
} else {
log.error("认证系统返回报文出错 {}", body);
}
} catch (Exception e) {
log.error("sign error", e);
@ -193,13 +197,12 @@ public class CheckLogin {
/**
* 利用BiConsumer实现foreach循环支持index
*
* @param biConsumer
* @param <T>
* @return
*/
public static <T> Consumer<T> forEachWithIndex(BiConsumer<T, Integer> biConsumer) {
/*这里说明一下我们每次传入forEach都是一个重新实例化的Consumer对象在lambada表达式中我们无法对int进行++操作,
我们模拟AtomicInteger对象写个getAndIncrement方法不能直接使用AtomicInteger哦*/
/*
这里说明一下我们每次传入forEach都是一个重新实例化的Consumer对象在lambada表达式中我们无法对int进行++操作,
我们模拟AtomicInteger对象写个getAndIncrement方法不能直接使用AtomicInteger哦
*/
class IncrementInt{
int i = 0;
public int getAndIncrement(){