|
|
@@ -129,7 +129,7 @@ public class LoginController {
|
|
|
|
|
|
String domain = RequestUtils.getHeader ( "domain" );
|
|
|
if(domain.contains("ydddl")){
|
|
|
- domain = getIp(domain);
|
|
|
+ domain = getDomainOrIp(domain);
|
|
|
}
|
|
|
if (domain.contains("ydddl")){
|
|
|
|
|
|
@@ -190,15 +190,29 @@ public class LoginController {
|
|
|
* @param url
|
|
|
* @return
|
|
|
*/
|
|
|
- public static String getIp(String url) {
|
|
|
- // 去掉 http:// 或 https://
|
|
|
- String withoutHttp = url.replaceAll("^https?://", "");
|
|
|
+ public static String getDomainOrIp(String url) {
|
|
|
+ if (url == null || url.isEmpty()) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ // 1. 去掉 http:// 或 https://
|
|
|
+ String withoutHttp = url.replaceFirst("^https?://", "");
|
|
|
+
|
|
|
+ // 2. 截取到第一个 : 或 / 之前(取出纯域名/IP)
|
|
|
+ int indexPort = withoutHttp.indexOf(":");
|
|
|
+ int indexPath = withoutHttp.indexOf("/");
|
|
|
+ int splitIndex = indexPort;
|
|
|
|
|
|
- // 截取到第一个 : 为止
|
|
|
- int index = withoutHttp.indexOf(":");
|
|
|
- if (index != -1) {
|
|
|
- return withoutHttp.substring(0, index);
|
|
|
+ if (indexPath != -1 && (splitIndex == -1 || indexPath < splitIndex)) {
|
|
|
+ splitIndex = indexPath;
|
|
|
}
|
|
|
+ if (splitIndex != -1) {
|
|
|
+ withoutHttp = withoutHttp.substring(0, splitIndex);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 去掉末尾的 ydddl(只去掉结尾的)
|
|
|
+ withoutHttp = withoutHttp.replaceFirst("ydddl$", "");
|
|
|
+
|
|
|
return withoutHttp;
|
|
|
}
|
|
|
|
|
|
@@ -233,7 +247,7 @@ public class LoginController {
|
|
|
|
|
|
String domain = RequestUtils.getHeader ( "domain" );
|
|
|
if(domain.contains("ydddl")){
|
|
|
- domain = getIp(domain);
|
|
|
+ domain = getDomainOrIp(domain);
|
|
|
}
|
|
|
if (domain.contains("ydddl")){
|
|
|
|
|
|
@@ -316,7 +330,7 @@ public class LoginController {
|
|
|
|
|
|
String domain = RequestUtils.getHeader ( "domain" );
|
|
|
if(domain.contains("ydddl")){
|
|
|
- domain = getIp(domain);
|
|
|
+ domain = getDomainOrIp(domain);
|
|
|
}
|
|
|
if (domain.contains("ydddl")){
|
|
|
|