parent
41fb2f2b2f
commit
8372e0d2b7
|
@ -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,6 +45,40 @@ 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) {
|
||||||
|
String token = null;
|
||||||
|
try {
|
||||||
|
// 自定义 TrustManager
|
||||||
|
TrustManager[] trustAllCerts = new TrustManager[]{
|
||||||
|
new X509TrustManager() {
|
||||||
|
public X509Certificate[] getAcceptedIssuers() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
long currentTimeMillis = System.currentTimeMillis();
|
||||||
String signature = generateSignature("appKey" + APP_KEY + "timestamp" + currentTimeMillis);
|
String signature = generateSignature("appKey" + APP_KEY + "timestamp" + currentTimeMillis);
|
||||||
logger.info("getBIPToken → 签名: {}", signature);
|
logger.info("getBIPToken → 签名: {}", signature);
|
||||||
|
@ -58,8 +93,6 @@ public class ApiService {
|
||||||
// return urlString;
|
// return urlString;
|
||||||
|
|
||||||
logger.info("getBIPToken → 构建URL: {}", urlString);
|
logger.info("getBIPToken → 构建URL: {}", urlString);
|
||||||
|
|
||||||
String token;
|
|
||||||
try {
|
try {
|
||||||
// 发送请求
|
// 发送请求
|
||||||
Request request = buildRequest(urlString);
|
Request request = buildRequest(urlString);
|
||||||
|
@ -71,8 +104,12 @@ public class ApiService {
|
||||||
token = null;
|
token = null;
|
||||||
}
|
}
|
||||||
// 处理响应
|
// 处理响应
|
||||||
return token;
|
logger.info("getBIPToken method completed successfully");
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.info("Error in getBIPToken", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Request buildRequest(String urlString) {
|
private static Request buildRequest(String urlString) {
|
||||||
|
|
Loading…
Reference in New Issue