Просмотр исходного кода

修复LINE Pay支付成功推送固定英文的问题

推送在linePayTaskExecutor异步线程执行,无请求级locale,
LocaleContextHolder回落JVM默认en_US命中英文语言包;
改为按收件人用户语言解析(MessageUtils新增显式Locale重载),
并修正zh_TW推送标题简体「消息」为繁体「訊息」。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
qmj 1 день назад
Родитель
Сommit
2416a9377e

+ 15 - 9
ruoyi-admin/src/main/java/com/ruoyi/app/pay/LinePayOrderNotificationService.java

@@ -3,6 +3,7 @@ package com.ruoyi.app.pay;
 import com.ruoyi.app.order.dto.OrderPushBodyDto;
 import com.ruoyi.app.utils.PayPush;
 import com.ruoyi.app.utils.event.PushEventService;
+import com.ruoyi.common.utils.LocaleUtils;
 import com.ruoyi.common.utils.MessageUtils;
 import com.ruoyi.system.domain.InfoUser;
 import com.ruoyi.system.domain.PosOrder;
@@ -12,6 +13,8 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.support.TransactionSynchronization;
+
+import java.util.Locale;
 import org.springframework.transaction.support.TransactionSynchronizationManager;
 
 /** Executes the existing one-time order log and push side effects after LINE payment capture. */
@@ -40,21 +43,24 @@ public class LinePayOrderNotificationService {
     private void pushPaymentSuccess(PosOrder order) {
         try {
             String ddId = String.valueOf(order.getDdId());
-            String title = MessageUtils.message("no.message.push.message");
             String body = OrderPushBodyDto.getJson(ddId, String.valueOf(order.getState()), 0);
             InfoUser user = order.getUserId() == null ? null : infoUserService.getById(order.getUserId());
             if (user != null) {
-                new PayPush().apppush(user.getCid(), title,
-                        MessageUtils.message("no.message.push.payment.success"), body);
-                pushEventService.PublisherEvent(user.getUserId(), title,
-                        MessageUtils.message("no.message.push.payment.success"), body);
+                // 推送常在异步线程执行(confirm 回调投递 linePayTaskExecutor),无请求级 locale,
+                // 必须按收件人用户语言解析,否则回落 JVM 默认语言(线上为英文)
+                Locale userLocale = LocaleUtils.getUserLocale(user.getUserId());
+                String title = MessageUtils.message("no.message.push.message", userLocale);
+                String content = MessageUtils.message("no.message.push.payment.success", userLocale);
+                new PayPush().apppush(user.getCid(), title, content, body);
+                pushEventService.PublisherEvent(user.getUserId(), title, content, body);
             }
             InfoUser merchant = order.getShId() == null ? null : infoUserService.getById(order.getShId());
             if (merchant != null) {
-                new PayPush().shpush(merchant.getCid(), title,
-                        MessageUtils.message("no.message.push.new.order"), body);
-                pushEventService.PublisherEvent(merchant.getUserId(), title,
-                        MessageUtils.message("no.message.push.new.order"), body);
+                Locale merchantLocale = LocaleUtils.getUserLocale(merchant.getUserId());
+                String title = MessageUtils.message("no.message.push.message", merchantLocale);
+                String content = MessageUtils.message("no.message.push.new.order", merchantLocale);
+                new PayPush().shpush(merchant.getCid(), title, content, body);
+                pushEventService.PublisherEvent(merchant.getUserId(), title, content, body);
             }
         } catch (Exception exception) {
             log.error("LINE Pay payment success push failed, ddId={}", order.getDdId(), exception);

+ 1 - 1
ruoyi-admin/src/main/resources/i18n/messages_zh_TW.properties

@@ -102,7 +102,7 @@ no.order.not.exist=訂單不存在
 no.order.place.success=下單成功
 no.order.id.error=訂單id不正確
 no.order.create.success=創建訂單成功
-no.message.push.message=
+no.message.push.message=
 no.message.push.delivery.personnel.receiving.order=騎手已接單
 no.message.push.new.order=有新訂單
 no.message.push.recharge.success=充值成功

+ 17 - 0
ruoyi-common/src/main/java/com/ruoyi/common/utils/MessageUtils.java

@@ -1,5 +1,6 @@
 package com.ruoyi.common.utils;
 
+import java.util.Locale;
 import org.springframework.context.MessageSource;
 import org.springframework.context.i18n.LocaleContextHolder;
 import com.ruoyi.common.utils.spring.SpringUtils;
@@ -23,4 +24,20 @@ public class MessageUtils
         MessageSource messageSource = SpringUtils.getBean(MessageSource.class);
         return messageSource.getMessage(code, args, LocaleContextHolder.getLocale());
     }
+
+
+    /**
+     * 按指定语言解析消息,供无请求上下文的线程(异步任务/定时任务)使用,
+     * 避免 LocaleContextHolder 回落到 JVM 默认语言
+     *
+     * @param code 消息键
+     * @param locale 指定语言(如按收件人用户语言)
+     * @param args 参数
+     * @return 获取国际化翻译值
+     */
+    public static String message(String code, Locale locale, Object... args)
+    {
+        MessageSource messageSource = SpringUtils.getBean(MessageSource.class);
+        return messageSource.getMessage(code, args, locale);
+    }
 }