Compare commits
2 Commits
987c7524f2
...
8af5148f06
Author | SHA1 | Date | |
---|---|---|---|
![]() |
8af5148f06 | ||
![]() |
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;
|
||||||
@ -122,50 +123,43 @@ public class CheckLogin {
|
|||||||
log.info("开始{}打卡 {} 的账号,密码为:{}", signMark == 0 ? "上班" : "下班", username, password);
|
log.info("开始{}打卡 {} 的账号,密码为:{}", signMark == 0 ? "上班" : "下班", username, password);
|
||||||
password = encrypt2ToMD5(password);
|
password = encrypt2ToMD5(password);
|
||||||
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 ssoToken = thirdBodyJson.getStr("ssoToken");
|
try (HttpResponse httpResponse = HttpRequest.post("http://oms.oa.unionpay.com/prod-api/atds/ds/" + signMark)
|
||||||
// http://oms.oa.unionpay.com/prod-api/atds/gcp/1
|
.header("Authorization", "Bearer " + thirdToken)
|
||||||
// String userInfoRes = HttpRequest.get("http://oms.oa.unionpay.com/prod-api/system/user/getUser")
|
.execute()) {
|
||||||
// .header("Authorization", "Bearer " + thirdToken)
|
JSONObject signJson = JSONUtil.parseObj(httpResponse.body());
|
||||||
// .header("ssoToken", ssoToken)
|
if ("200".equals(signJson.getStr("code"))) {
|
||||||
// .execute().body();
|
String signDateTime = DateUtil.formatDateTime(signJson.getDate("data"));
|
||||||
// JSONObject userInfoJson = JSONUtil.parseObj(userInfoRes);
|
result = true;
|
||||||
// log.info("nikename: {}", userInfoJson.getJSONObject("user").getJSONObject("user").getStr("nickName"));
|
log.info("{} 打卡时间 {}", user.getUsername(), signDateTime);
|
||||||
String signUrl = "http://oms.oa.unionpay.com/prod-api/atds/ds/" + signMark;
|
} else {
|
||||||
String resultBody = HttpRequest.post(signUrl)
|
log.error("签到接口出错 {}", signJson);
|
||||||
.header("Authorization", "Bearer " + thirdToken)
|
}
|
||||||
.header("ssoToken", ssoToken)
|
}
|
||||||
.execute().body();
|
}
|
||||||
JSONObject signJson = JSONUtil.parseObj(resultBody);
|
|
||||||
if ("200".equals(signJson.getStr("code"))) {
|
|
||||||
String signDateTime = DateUtil.formatDateTime(signJson.getDate("data"));
|
|
||||||
result = true;
|
|
||||||
log.info("{} 打卡时间 {}", username, signDateTime);
|
|
||||||
} else {
|
} else {
|
||||||
log.error("签到接口出错 {}", resultBody);
|
log.error("认证系统返回报文出错 {}", response.body());
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
log.error("认证系统返回报文出错 {}", body);
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("sign error", e);
|
log.error("sign error", e);
|
||||||
@ -205,13 +199,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