From fa57a6b231778f06c1c9a4b4a47bfac3cc392290 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=82=E6=A2=A6=E6=8A=80=E6=9C=AF?= <596392912@qq.com> Date: Sat, 11 May 2019 13:22:41 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E4=BF=AE=E5=A4=8D=E5=8D=95=E5=85=AC?= =?UTF-8?q?=E4=BC=97=E5=8F=B7=E6=B6=88=E6=81=AF=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dreamlu/weixin/spring/MsgInterceptor.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/spring-boot-starter-weixin/src/main/java/net/dreamlu/weixin/spring/MsgInterceptor.java b/spring-boot-starter-weixin/src/main/java/net/dreamlu/weixin/spring/MsgInterceptor.java index 7affa38..93a3bfa 100644 --- a/spring-boot-starter-weixin/src/main/java/net/dreamlu/weixin/spring/MsgInterceptor.java +++ b/spring-boot-starter-weixin/src/main/java/net/dreamlu/weixin/spring/MsgInterceptor.java @@ -10,6 +10,7 @@ import net.dreamlu.weixin.properties.DreamWeixinProperties; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.core.annotation.AnnotationUtils; +import org.springframework.util.StringUtils; import org.springframework.web.method.HandlerMethod; import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; @@ -41,7 +42,9 @@ public class MsgInterceptor extends HandlerInterceptorAdapter { WxApi wxApi = AnnotationUtils.getAnnotation(beanType, WxApi.class); String appId = request.getParameter(weixinProperties.getAppIdKey()); if (wxApi != null) { - ApiConfigKit.setThreadLocalAppId(appId); + if (StringUtils.hasText(appId)) { + ApiConfigKit.setThreadLocalAppId(appId); + } return true; } // 判断是否多公众号,将 appId 与当前线程绑定,以便在后续操作中方便获取ApiConfig对象: @@ -49,20 +52,20 @@ public class MsgInterceptor extends HandlerInterceptorAdapter { boolean isWx = bean instanceof MsgController; String token; if (isWx) { - token = ApiConfigKit.getApiConfig(appId).getToken(); + if (StringUtils.hasText(appId)) { + ApiConfigKit.setThreadLocalAppId(appId); + token = ApiConfigKit.getApiConfig(appId).getToken(); + } else { + token = ApiConfigKit.getApiConfig().getToken(); + } } else { token = WxaConfigKit.getWxaConfig().getToken(); } - // 如果是服务器配置请求,则配置服务器并返回 if (isConfigServerRequest(request)) { configServer(request, response, token); return false; } - // 判断是否多公众号,将 appId 与当前线程绑定,以便在后续操作中方便获取ApiConfig对象: - if (isWx) { - ApiConfigKit.setThreadLocalAppId(appId); - } // 对开发测试更加友好 if (ApiConfigKit.isDevMode()) { return true; -- GitLab