From e16302f9d475c7cc4dd18c5abf1a23cb5502e362 Mon Sep 17 00:00:00 2001
From: whyclxw <810412026@qq.com>
Date: 星期三, 28 五月 2025 14:57:56 +0800
Subject: [PATCH] 密码验证加-

---
 src/main/java/com/whyc/util/MessageUtils.java |   38 ++++++++++++++++++++++++++------------
 1 files changed, 26 insertions(+), 12 deletions(-)

diff --git a/src/main/java/com/whyc/util/MessageUtils.java b/src/main/java/com/whyc/util/MessageUtils.java
index 19a12d8..58bceae 100644
--- a/src/main/java/com/whyc/util/MessageUtils.java
+++ b/src/main/java/com/whyc/util/MessageUtils.java
@@ -1,18 +1,13 @@
 package com.whyc.util;
 
 import com.whyc.config.I18nLocaleResolver;
-import lombok.var;
-import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.MessageSource;
-import org.springframework.context.i18n.LocaleContextHolder;
 import org.springframework.context.support.ResourceBundleMessageSource;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.PostConstruct;
 import java.nio.charset.StandardCharsets;
 import java.util.Locale;
-import java.util.Objects;
 
 @Component
 public class MessageUtils {
@@ -35,17 +30,21 @@
     @Value("${spring.messages.basename}")
     private String basename;
 
-    private final I18nLocaleResolver resolver;
+    private final  I18nLocaleResolver resolver;
 
     private static I18nLocaleResolver customLocaleResolver;
 
     private static String path;
 
-
+    static{
+        if(customLocaleResolver == null) {
+            customLocaleResolver = new I18nLocaleResolver();
+            path = "i18n/message";
+        }
+    }
     public MessageUtils(I18nLocaleResolver resolver) {
         this.resolver = resolver;
     }
-
 
     @PostConstruct
     public void init() {
@@ -64,16 +63,31 @@
         return getMessage(code, null, code, locale);
     }
 
+    /**
+     * 鑾峰彇 鍥介檯鍖栧悗鍐呭淇℃伅
+     *
+     * @param code 鍥介檯鍖杒ey
+     * @return 鍥介檯鍖栧悗鍐呭淇℃伅
+     */
+    public static String getMessageSocket(String code, String lang) {
+        Locale locale = Locale.SIMPLIFIED_CHINESE;
+        if (lang != null) {
+            if ((lang.contains("zh"))) {
+                locale = Locale.SIMPLIFIED_CHINESE;
+            } else { //涓嶆槸涓枃,鍒欓噰鐢╡n_US
+                locale = Locale.US;
+            }
+        }
+        return getMessage(code, null, code, locale);
+    }
+
     public static String getMessage(String code, Object[] args, String defaultMessage, Locale locale) {
         ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
+        messageSource.setDefaultEncoding(StandardCharsets.UTF_8.toString());
         //鍒ゆ柇locale,濡傛灉涓嶆槸zh鎴杄n,鍒欎娇鐢ㄨ嫳鏂�
         String language = locale.getLanguage();
-        /*else {
-            messageSource.setDefaultEncoding(StandardCharsets.UTF_8.toString());
-        }*/
         if((language.equals("zh"))){
             locale = Locale.SIMPLIFIED_CHINESE;
-            messageSource.setDefaultEncoding("GBK");
         }else{ //涓嶆槸涓枃,鍒欓噰鐢╡n_US
             locale = Locale.US;
         }

--
Gitblit v1.9.1