Changes
This commit is contained in:
parent
1ba009cf9e
commit
e34403c39c
@ -12,6 +12,7 @@ import cn.hutool.core.util.NumberUtil;
|
|||||||
import cn.hutool.core.util.RandomUtil;
|
import cn.hutool.core.util.RandomUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.http.HttpRequest;
|
import cn.hutool.http.HttpRequest;
|
||||||
|
import cn.hutool.http.HttpResponse;
|
||||||
import cn.hutool.json.JSONObject;
|
import cn.hutool.json.JSONObject;
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
@ -120,40 +121,43 @@ public class CheckLogin {
|
|||||||
String password = encrypt2ToMD5(user.getPassword());
|
String password = encrypt2ToMD5(user.getPassword());
|
||||||
String username = user.getUsername();
|
String username = user.getUsername();
|
||||||
log.info("加密密码为:{}", password);
|
log.info("加密密码为:{}", password);
|
||||||
String body = HttpRequest.post("https://login.oa.unionpay.com/idsapi/portal/Login")
|
try (HttpResponse response = HttpRequest.post("https://login.oa.unionpay.com/idsapi/portal/Login")
|
||||||
.form("username", username)
|
.form("username", username)
|
||||||
.form("password", password)
|
.form("password", password)
|
||||||
.form("saveUsername", "false")
|
.form("saveUsername", "false")
|
||||||
.form("savePassword", "false")
|
.form("savePassword", "false")
|
||||||
.form("loginType", "normal")
|
.form("loginType", "normal")
|
||||||
.form("code", "")
|
.form("code", "")
|
||||||
.execute().body();
|
.execute()) {
|
||||||
JSONObject data = JSONUtil.parseObj(body).getJSONObject("data");
|
JSONObject data = JSONUtil.parseObj(response.body()).getJSONObject("data");
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
String token = data.getStr("token");
|
String token = data.getStr("token");
|
||||||
log.info("认证系统返回token {}", token);
|
log.info("认证系统返回token {}", token);
|
||||||
String thirdBody = HttpRequest
|
try (HttpResponse thirdResponse = HttpRequest
|
||||||
.get("http://oms.oa.unionpay.com/prod-api/checkTokenThenLogin?personType=0&token=" + token)
|
.get("http://oms.oa.unionpay.com/prod-api/checkTokenThenLogin?personType=0&token=" + token)
|
||||||
.execute().body();
|
.execute()) {
|
||||||
JSONObject thirdBodyJson = JSONUtil.parseObj(thirdBody);
|
JSONObject thirdBodyJson = JSONUtil.parseObj(thirdResponse.body());
|
||||||
if (!"200".equals(thirdBodyJson.getStr("code"))) {
|
if (!"200".equals(thirdBodyJson.getStr("code"))) {
|
||||||
log.error("签到系统返回报文出错 {}", thirdBodyJson);
|
log.error("签到系统返回报文出错 {}", thirdBodyJson);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
String thirdToken = thirdBodyJson.getStr("localToken");
|
String thirdToken = thirdBodyJson.getStr("localToken");
|
||||||
String resultBody = HttpRequest.post("http://oms.oa.unionpay.com/prod-api/atds/ds/" + signMark)
|
try (HttpResponse httpResponse = HttpRequest.post("http://oms.oa.unionpay.com/prod-api/atds/ds/" + signMark)
|
||||||
.header("Authorization", "Bearer " + thirdToken)
|
.header("Authorization", "Bearer " + thirdToken)
|
||||||
.execute().body();
|
.execute()) {
|
||||||
JSONObject signJson = JSONUtil.parseObj(resultBody);
|
JSONObject signJson = JSONUtil.parseObj(httpResponse.body());
|
||||||
if ("200".equals(signJson.getStr("code"))) {
|
if ("200".equals(signJson.getStr("code"))) {
|
||||||
String signDateTime = DateUtil.formatDateTime(signJson.getDate("data"));
|
String signDateTime = DateUtil.formatDateTime(signJson.getDate("data"));
|
||||||
result = true;
|
result = true;
|
||||||
log.info("{} 打卡时间 {}", user.getUsername(), signDateTime);
|
log.info("{} 打卡时间 {}", user.getUsername(), signDateTime);
|
||||||
} else {
|
} else {
|
||||||
log.error("签到接口出错 {}", resultBody);
|
log.error("签到接口出错 {}", signJson);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.error("认证系统返回报文出错 {}", body);
|
log.error("认证系统返回报文出错 {}", response.body());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("sign error", e);
|
log.error("sign error", e);
|
||||||
@ -193,13 +197,12 @@ public class CheckLogin {
|
|||||||
/**
|
/**
|
||||||
* 利用BiConsumer实现foreach循环支持index
|
* 利用BiConsumer实现foreach循环支持index
|
||||||
*
|
*
|
||||||
* @param biConsumer
|
|
||||||
* @param <T>
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public static <T> Consumer<T> forEachWithIndex(BiConsumer<T, Integer> biConsumer) {
|
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{
|
class IncrementInt{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
public int getAndIncrement(){
|
public int getAndIncrement(){
|
||||||
|
Loading…
Reference in New Issue
Block a user