提交内容:定时任务

备注:定时推送单据至BIP
提交人:邹江涛
This commit is contained in:
zoujiangtao 2024-12-18 09:30:18 +08:00
parent 41fb2f2b2f
commit 8372e0d2b7
1 changed files with 61 additions and 24 deletions

View File

@ -30,6 +30,7 @@ import java.nio.charset.StandardCharsets;
import java.security.cert.X509Certificate;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.logging.Level;
/**
* @Description
@ -44,35 +45,71 @@ public class ApiService {
private static final String API_ENDPOINT = "/iuap-api-auth/open-auth/selfAppAuth/getAccessToken";
public static String getBIPToken(String domainName) {
long currentTimeMillis = System.currentTimeMillis();
String signature = generateSignature("appKey" + APP_KEY + "timestamp" + currentTimeMillis);
logger.info("getBIPToken → 签名: {}", signature);
String token = null;
try {
// 自定义 TrustManager
TrustManager[] trustAllCerts = new TrustManager[]{
new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return null;
}
// 禁用 SSL 证书验证
disableSSLCertificateChecking();
// 构建URL
String urlString = domainName + API_ENDPOINT +
"?appKey=" + APP_KEY +
"&timestamp=" + currentTimeMillis +
"&signature=" + signature;
public void checkClientTrusted(X509Certificate[] certs, String authType) {
}
public void checkServerTrusted(X509Certificate[] certs, String authType) {
}
}
};
// 安装所有信任的管理器
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
// 自定义 HostnameVerifier
HostnameVerifier hostnameVerifier = new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
logger.info("Verifying hostname: " + hostname);
return true; // 始终返回 true绕过验证
}
};
// 设置自定义 HostnameVerifier
HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier);
long currentTimeMillis = System.currentTimeMillis();
String signature = generateSignature("appKey" + APP_KEY + "timestamp" + currentTimeMillis);
logger.info("getBIPToken → 签名: {}", signature);
// 禁用 SSL 证书验证
disableSSLCertificateChecking();
// 构建URL
String urlString = domainName + API_ENDPOINT +
"?appKey=" + APP_KEY +
"&timestamp=" + currentTimeMillis +
"&signature=" + signature;
// return urlString;
logger.info("getBIPToken → 构建URL: {}", urlString);
String token;
try {
// 发送请求
Request request = buildRequest(urlString);
Response response = client.newCall(request).execute();
logger.info("getBIPToken → 获取返回数据:{}", response);
token = handleResponse(response);
logger.info("getBIPToken → 构建URL: {}", urlString);
try {
// 发送请求
Request request = buildRequest(urlString);
Response response = client.newCall(request).execute();
logger.info("getBIPToken → 获取返回数据:{}", response);
token = handleResponse(response);
} catch (Exception e) {
logger.error("getBIPToken → 请求失败: ", e);
token = null;
}
// 处理响应
logger.info("getBIPToken method completed successfully");
} catch (Exception e) {
logger.error("getBIPToken → 请求失败: ", e);
token = null;
logger.info("Error in getBIPToken", e);
}
// 处理响应
return token;
return token;
}
private static Request buildRequest(String urlString) {
@ -238,7 +275,7 @@ public class ApiService {
if ("TF、NC、OF".contains(objects[0].getString("bankpaystatus"))) {
dynamic.set("shkd_pushstatus", "结算失败");
} else if ("TS".equals(objects[0].getString("bankpaystatus"))){
} else if ("TS".equals(objects[0].getString("bankpaystatus"))) {
dynamic.set("shkd_pushstatus", "已结算");
}