使用原生方式对接口进行测试 修复授权管理页面重置AK,SK未写入到数据库中的异常

使用原生方式对接口进行测试
修复授权管理页面重置AK,SK未写入到数据库中的异常
This commit is contained in:
xlh12306
2025-05-28 22:22:39 +08:00
parent 0b10096f1c
commit 2d62bad2a9
4 changed files with 76 additions and 52 deletions

View File

@ -8,8 +8,6 @@ import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.client.RestTemplate;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Iterator;
import java.util.Map;
@ -32,42 +30,18 @@ public class RestUtil {
// 微服务版集成企业微信单点登录
// 因为微服务版没有端口号,导致 SpringContextUtils.getDomain() 方法获取的域名的端口号变成了:-1所以出问题了只需要把这个-1给去掉就可以了。
String port=":-1";
//单元测试导致无端口号的问题
if (!domain.endsWith(port)){
checkAndAddPort();
}
if (domain.endsWith(port)) {
domain = domain.substring(0, domain.length() - 3);
}
}
return domain;
}
private static void checkAndAddPort() {
try {
URL url = new URL(domain);
int port = url.getPort();
if (port == -1) {
domain = domain+":"+getPort();
}
} catch (MalformedURLException e) {
log.warn("获取端口号异常");
}
}
private static String getPath() {
if (path == null) {
path = SpringContextUtils.getApplicationContext().getEnvironment().getProperty("server.servlet.context-path");
}
return oConvertUtils.getString(path);
}
private static String getPort() {
String property = SpringContextUtils.getApplicationContext().getEnvironment().getProperty("server.port");
if (StringUtils.isEmpty(property)||"0".equals(property)) {
property = "8080";
}
return oConvertUtils.getString(property);
}
public static String getBaseUrl() {
String basepath = getDomain() + getPath();