Quellcode durchsuchen

移动端登陆IP切分调整

徐滕 vor 1 Woche
Ursprung
Commit
ac73f4519c

+ 24 - 10
jeeplus-auth/src/main/java/com/jeeplus/auth/controller/LoginController.java

@@ -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")){
 

+ 23 - 9
jeeplus-modules/jeeplus-system/src/main/java/com/jeeplus/sys/utils/TenantUtils.java

@@ -26,7 +26,7 @@ public class TenantUtils {
          */
         String domain = RequestUtils.getHeader ( "domain" );
         if(domain.contains("ydddl")){
-            domain = getIp(domain);
+            domain = getDomainOrIp(domain);
         }
         if ( domain == null ) {
             return CommonConstants.DEFAULT_TENANT_ID; // 返回默认租户
@@ -65,15 +65,29 @@ public class TenantUtils {
      * @param url
      * @return
      */
-    public static String getIp(String url) {
-        // 去掉 http:// 或 https://
-        String withoutHttp = url.replaceAll("^https?://", "");
-
-        // 截取到第一个 : 为止
-        int index = withoutHttp.indexOf(":");
-        if (index != -1) {
-            return withoutHttp.substring(0, index);
+    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;
+
+        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;
     }