From ae436e5e2a1c7ee6ed85a9b63116e29972237934 Mon Sep 17 00:00:00 2001 From: 007 <007gzs@gmail.com> Date: Wed, 2 May 2018 14:31:41 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix=20=E5=A4=9A=E6=AC=A1=E6=8E=88=E6=9D=83?= =?UTF-8?q?=E6=97=B6=EF=BC=8CRefreshToken=20=E6=B2=A1=E6=9C=89=E5=88=B7?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/impl/WxOpenComponentServiceImpl.java | 20 ++++++++++--------- 1 file changed, 11 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 cb9062c7e3..680ba0243b 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 String route(final WxOpenXmlMessage wxMessage) throws WxErrorException { 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,17 @@ public WxOpenQueryAuthResult getQueryAuth(String authorizationCode) throws WxErr 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); + + 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 From 2b613a1ecd8b35645551c32b65725518b726590d Mon Sep 17 00:00:00 2001 From: 007 <007gzs@gmail.com> Date: Wed, 2 May 2018 14:34:19 +0800 Subject: [PATCH 2/2] =?UTF-8?q?null=20=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/open/api/impl/WxOpenComponentServiceImpl.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 680ba0243b..35207809f7 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 @@ -205,7 +205,9 @@ public WxOpenQueryAuthResult getQueryAuth(String authorizationCode) throws WxErr jsonObject.addProperty("authorization_code", authorizationCode); String responseContent = post(API_QUERY_AUTH_URL, jsonObject.toString()); 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(),