From e119931fb4f8baa9f4fb24e5391cbbbbec4d6386 Mon Sep 17 00:00:00 2001 From: wenc000 <450292408@qq.com> Date: Wed, 13 May 2020 17:07:57 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=BE=AE=E4=BF=A1=E7=99=BB?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/pojo/WechatMiniAppProperties.java | 11 ----------- .../common/wechat/filter/WechatMiniAppFilter.java | 15 +++++++++++---- .../impl/WechatMiniAppAuthServiceImpl.java | 3 +++ 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/cloud-common-wechat/src/main/java/com/cm/common/wechat/config/pojo/WechatMiniAppProperties.java b/cloud-common-wechat/src/main/java/com/cm/common/wechat/config/pojo/WechatMiniAppProperties.java index df612f1..5fbe755 100644 --- a/cloud-common-wechat/src/main/java/com/cm/common/wechat/config/pojo/WechatMiniAppProperties.java +++ b/cloud-common-wechat/src/main/java/com/cm/common/wechat/config/pojo/WechatMiniAppProperties.java @@ -23,7 +23,6 @@ public class WechatMiniAppProperties { private String grantType; private String appKey; private String appSecret; - private String configToken; public Boolean getActive() { return active; @@ -73,14 +72,6 @@ public class WechatMiniAppProperties { this.appSecret = appSecret; } - public String getConfigToken() { - return configToken == null ? "" : configToken; - } - - public void setConfigToken(String configToken) { - this.configToken = configToken; - } - @Override public String toString() { final StringBuilder sb = new StringBuilder("{"); @@ -96,8 +87,6 @@ public class WechatMiniAppProperties { .append(appKey).append('\"'); sb.append(",\"appSecret\":\"") .append(appSecret).append('\"'); - sb.append(",\"configToken\":\"") - .append(configToken).append('\"'); sb.append('}'); return sb.toString(); } diff --git a/cloud-common-wechat/src/main/java/com/cm/common/wechat/filter/WechatMiniAppFilter.java b/cloud-common-wechat/src/main/java/com/cm/common/wechat/filter/WechatMiniAppFilter.java index e745b5b..9563d36 100644 --- a/cloud-common-wechat/src/main/java/com/cm/common/wechat/filter/WechatMiniAppFilter.java +++ b/cloud-common-wechat/src/main/java/com/cm/common/wechat/filter/WechatMiniAppFilter.java @@ -34,8 +34,14 @@ public class WechatMiniAppFilter implements Filter { private static final Logger LOG = LoggerFactory.getLogger(WechatMiniAppFilter.class); private AntPathMatcher antPathMatcher; - - private static final String WECHAT_MINI_APP_LOGIN_URL = String.format("/**%s/auth/login", ISystemConstant.WECHAT_MINI_APP_PREFIX); + /** + * 授权登录 + */ + private static final String WECHAT_MINI_APP_AUTH_LOGIN_URL = String.format("/**%s/auth/login", ISystemConstant.WECHAT_MINI_APP_PREFIX); + /** + * 认证登录 + */ + private static final String WECHAT_MINI_APP_SIGN_LOGIN_URL = String.format("/**%s/sign/login", ISystemConstant.WECHAT_MINI_APP_PREFIX); /** * 微信类放行 */ @@ -57,9 +63,10 @@ public class WechatMiniAppFilter implements Filter { HttpServletResponse response = (HttpServletResponse) servletResponse; String requestUri = request.getRequestURI(); - boolean isLogin = antPathMatcher.match(WECHAT_MINI_APP_LOGIN_URL, requestUri); + boolean isLogin = antPathMatcher.match(WECHAT_MINI_APP_AUTH_LOGIN_URL, requestUri) || + antPathMatcher.match(WECHAT_MINI_APP_SIGN_LOGIN_URL, requestUri); if (isLogin) { - + filterChain.doFilter(request, response); return; } diff --git a/cloud-common-wechat/src/main/java/com/cm/common/wechat/service/impl/WechatMiniAppAuthServiceImpl.java b/cloud-common-wechat/src/main/java/com/cm/common/wechat/service/impl/WechatMiniAppAuthServiceImpl.java index 509067f..e72224f 100644 --- a/cloud-common-wechat/src/main/java/com/cm/common/wechat/service/impl/WechatMiniAppAuthServiceImpl.java +++ b/cloud-common-wechat/src/main/java/com/cm/common/wechat/service/impl/WechatMiniAppAuthServiceImpl.java @@ -49,6 +49,9 @@ public class WechatMiniAppAuthServiceImpl implements IWechatMiniAppAuthService { if (wechatMiniAppProperties == null) { throw new SystemException("未有相关配置"); } + if (wechatMiniAppProperties.getActive() == null || !wechatMiniAppProperties.getActive()) { + throw new SystemException("未激活小程序配置"); + } Map params = new HashMap<>(2); params.put("appid", wechatMiniAppProperties.getAppKey()); params.put("secret", wechatMiniAppProperties.getAppSecret());