From 9ff53a59f94c26310a03e15651a833da38580276 Mon Sep 17 00:00:00 2001 From: 007gzs <007gzs@gmail.com> Date: Wed, 2 May 2018 14:47:53 +0800 Subject: [PATCH] =?UTF-8?q?#568=20=E4=BF=AE=E5=A4=8D=E4=B8=89=E6=96=B9?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E5=A4=9A=E6=AC=A1=E6=8E=88=E6=9D=83=E6=97=B6?= =?UTF-8?q?=EF=BC=8CRefreshToken=20=E6=B2=A1=E6=9C=89=E5=88=B7=E6=96=B0?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix 多次授权时,RefreshToken 没有刷新 * null 判断 --- .../api/impl/WxOpenComponentServiceImpl.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenComponentServiceImpl.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenComponentServiceImpl.java index cb9062c7..35207809 100644 --- a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenComponentServiceImpl.java +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenComponentServiceImpl.java @@ -193,14 +193,6 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService { if (queryAuth == null || queryAuth.getAuthorizationInfo() == null || queryAuth.getAuthorizationInfo().getAuthorizerAppid() == null) { throw new NullPointerException("getQueryAuth"); } - WxOpenAuthorizationInfo authorizationInfo = queryAuth.getAuthorizationInfo(); - if (authorizationInfo.getAuthorizerAccessToken() != null) { - getWxOpenConfigStorage().updateAuthorizerAccessToken(authorizationInfo.getAuthorizerAppid(), - authorizationInfo.getAuthorizerAccessToken(), authorizationInfo.getExpiresIn()); - } - if (authorizationInfo.getAuthorizerRefreshToken() != null) { - getWxOpenConfigStorage().setAuthorizerRefreshToken(authorizationInfo.getAuthorizerAppid(), authorizationInfo.getAuthorizerRefreshToken()); - } return "success"; } return ""; @@ -212,7 +204,19 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService { jsonObject.addProperty("component_appid", getWxOpenConfigStorage().getComponentAppId()); jsonObject.addProperty("authorization_code", authorizationCode); String responseContent = post(API_QUERY_AUTH_URL, jsonObject.toString()); - return WxOpenGsonBuilder.create().fromJson(responseContent, WxOpenQueryAuthResult.class); + WxOpenQueryAuthResult queryAuth = WxOpenGsonBuilder.create().fromJson(responseContent, WxOpenQueryAuthResult.class); + if (queryAuth == null || queryAuth.getAuthorizationInfo() == null) { + return queryAuth; + } + WxOpenAuthorizationInfo authorizationInfo = queryAuth.getAuthorizationInfo(); + if (authorizationInfo.getAuthorizerAccessToken() != null) { + getWxOpenConfigStorage().updateAuthorizerAccessToken(authorizationInfo.getAuthorizerAppid(), + authorizationInfo.getAuthorizerAccessToken(), authorizationInfo.getExpiresIn()); + } + if (authorizationInfo.getAuthorizerRefreshToken() != null) { + getWxOpenConfigStorage().setAuthorizerRefreshToken(authorizationInfo.getAuthorizerAppid(), authorizationInfo.getAuthorizerRefreshToken()); + } + return queryAuth; } @Override