Skip to content

Commit

Permalink
🎨【小程序】路由规则使用异步时,当前的appId没有传入到子线程,导致wxMaService在子线程中无法取到父线程的appId。 (#2961
Browse files Browse the repository at this point in the history
)
  • Loading branch information
biubiubiu3971 authored Mar 24, 2023
1 parent ee94e6d commit bae84e1
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaMessage;
import cn.binarywang.wx.miniapp.util.WxMaConfigHolder;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import lombok.Data;
import me.chanjar.weixin.common.api.WxErrorExceptionHandler;
Expand Down Expand Up @@ -127,14 +128,15 @@ public WxMaXmlOutMessage route(final WxMaMessage wxMessage, final Map<String, Ob
if (matchRules.size() == 0) {
return null;
}

String miniAppId = WxMaConfigHolder.get();
final List<Future<?>> futures = new ArrayList<>();
WxMaXmlOutMessage result = null;
for (final WxMaMessageRouterRule rule : matchRules) {
// 返回最后一个非异步的rule的执行结果
if (rule.isAsync()) {
futures.add(
this.executorService.submit(() -> {
this.wxMaService.switchoverTo(miniAppId);
rule.service(wxMessage, context, WxMaMessageRouter.this.wxMaService, WxMaMessageRouter.this.sessionManager, WxMaMessageRouter.this.exceptionHandler);
})
);
Expand Down

0 comments on commit bae84e1

Please sign in to comment.