提交内容:定时任务

备注:定时推送单据至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.security.cert.X509Certificate;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import java.util.logging.Level;
/** /**
* @Description * @Description
@ -44,35 +45,71 @@ public class ApiService {
private static final String API_ENDPOINT = "/iuap-api-auth/open-auth/selfAppAuth/getAccessToken"; private static final String API_ENDPOINT = "/iuap-api-auth/open-auth/selfAppAuth/getAccessToken";
public static String getBIPToken(String domainName) { public static String getBIPToken(String domainName) {
long currentTimeMillis = System.currentTimeMillis(); String token = null;
String signature = generateSignature("appKey" + APP_KEY + "timestamp" + currentTimeMillis); try {
logger.info("getBIPToken → 签名: {}", signature); // 自定义 TrustManager
TrustManager[] trustAllCerts = new TrustManager[]{
new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return null;
}
// 禁用 SSL 证书验证 public void checkClientTrusted(X509Certificate[] certs, String authType) {
disableSSLCertificateChecking(); }
// 构建URL
String urlString = domainName + API_ENDPOINT + public void checkServerTrusted(X509Certificate[] certs, String authType) {
"?appKey=" + APP_KEY + }
"&timestamp=" + currentTimeMillis + }
"&signature=" + signature; };
// 安装所有信任的管理器
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; // return urlString;
logger.info("getBIPToken → 构建URL: {}", urlString); logger.info("getBIPToken → 构建URL: {}", urlString);
try {
String token; // 发送请求
try { Request request = buildRequest(urlString);
// 发送请求 Response response = client.newCall(request).execute();
Request request = buildRequest(urlString); logger.info("getBIPToken → 获取返回数据:{}", response);
Response response = client.newCall(request).execute(); token = handleResponse(response);
logger.info("getBIPToken → 获取返回数据:{}", response); } catch (Exception e) {
token = handleResponse(response); logger.error("getBIPToken → 请求失败: ", e);
token = null;
}
// 处理响应
logger.info("getBIPToken method completed successfully");
} catch (Exception e) { } catch (Exception e) {
logger.error("getBIPToken → 请求失败: ", e); logger.info("Error in getBIPToken", e);
token = null;
} }
// 处理响应
return token;
return token;
} }
private static Request buildRequest(String urlString) { private static Request buildRequest(String urlString) {
@ -238,7 +275,7 @@ public class ApiService {
if ("TF、NC、OF".contains(objects[0].getString("bankpaystatus"))) { if ("TF、NC、OF".contains(objects[0].getString("bankpaystatus"))) {
dynamic.set("shkd_pushstatus", "结算失败"); dynamic.set("shkd_pushstatus", "结算失败");
} else if ("TS".equals(objects[0].getString("bankpaystatus"))){ } else if ("TS".equals(objects[0].getString("bankpaystatus"))) {
dynamic.set("shkd_pushstatus", "已结算"); dynamic.set("shkd_pushstatus", "已结算");
} }