From 3d54c1fe199cf2f0ef1873804539a672cbdc755e Mon Sep 17 00:00:00 2001 From: Element Date: Tue, 21 Jul 2020 00:18:24 +0800 Subject: [PATCH] =?UTF-8?q?fix=20#1590=20=E6=8F=90=E5=8F=8A=E7=9A=84me.cha?= =?UTF-8?q?njar.weixin.open.api.impl.WxOpenComponentServiceImpl#getAuthori?= =?UTF-8?q?zerAccessToken()=E5=88=B7=E6=96=B0AccessToken=E5=90=8E=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E5=90=8C=E6=AD=A5=E5=AF=B9=E5=BA=94=E7=9A=84refreshTo?= =?UTF-8?q?ken?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/open/api/WxOpenConfigStorage.java | 7 +++++++ .../api/impl/WxOpenComponentServiceImpl.java | 1 + .../api/impl/WxOpenInMemoryConfigStorage.java | 5 +++++ .../bean/WxOpenAuthorizerAccessToken.java | 20 ++++--------------- ...xOpenAuthorizerAccessTokenGsonAdapter.java | 1 + 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenConfigStorage.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenConfigStorage.java index 4d1c2b136d..4b496b30d3 100644 --- a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenConfigStorage.java +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenConfigStorage.java @@ -208,6 +208,13 @@ public interface WxOpenConfigStorage { */ void setAuthorizerRefreshToken(String appId, String authorizerRefreshToken); + /** + * setAuthorizerRefreshToken(String appId, String authorizerRefreshToken) 方法重载方法 + * @param appId the app id + * @param authorizerRefreshToken the authorizer refresh token + */ + void updateAuthorizerRefreshToken(String appId, String authorizerRefreshToken); + /** * Gets authorizer access token. * 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 5e54929a04..e56c9c7d10 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 @@ -390,6 +390,7 @@ public String getAuthorizerAccessToken(String appId, boolean forceRefresh) throw WxOpenAuthorizerAccessToken wxOpenAuthorizerAccessToken = WxOpenAuthorizerAccessToken.fromJson(responseContent); config.updateAuthorizerAccessToken(appId, wxOpenAuthorizerAccessToken); + config.updateAuthorizerRefreshToken(appId,wxOpenAuthorizerAccessToken.getAuthorizerRefreshToken()); return config.getAuthorizerAccessToken(appId); } catch (InterruptedException e) { throw new RuntimeException(e); diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenInMemoryConfigStorage.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenInMemoryConfigStorage.java index 723ec3806e..c79def87eb 100644 --- a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenInMemoryConfigStorage.java +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenInMemoryConfigStorage.java @@ -157,6 +157,11 @@ public void setAuthorizerRefreshToken(String appId, String authorizerRefreshToke updateToken(authorizerRefreshTokens, appId, authorizerRefreshToken, null); } + @Override + public void updateAuthorizerRefreshToken(String appId, String authorizerRefreshToken) { + this.setAuthorizerRefreshToken(appId,authorizerRefreshToken); + } + @Override public String getAuthorizerAccessToken(String appId) { return getTokenString(authorizerAccessTokens, appId); diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/WxOpenAuthorizerAccessToken.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/WxOpenAuthorizerAccessToken.java index 9b86412bb3..9a558ab776 100644 --- a/weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/WxOpenAuthorizerAccessToken.java +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/WxOpenAuthorizerAccessToken.java @@ -1,5 +1,6 @@ package me.chanjar.weixin.open.bean; +import lombok.Data; import me.chanjar.weixin.open.util.json.WxOpenGsonBuilder; import java.io.Serializable; @@ -7,30 +8,17 @@ /** * @author 007 */ +@Data public class WxOpenAuthorizerAccessToken implements Serializable { private static final long serialVersionUID = -4069745419280727420L; private String authorizerAccessToken; + private String authorizerRefreshToken; + private int expiresIn = -1; public static WxOpenAuthorizerAccessToken fromJson(String json) { return WxOpenGsonBuilder.create().fromJson(json, WxOpenAuthorizerAccessToken.class); } - - public String getAuthorizerAccessToken() { - return authorizerAccessToken; - } - - public void setAuthorizerAccessToken(String authorizerAccessToken) { - this.authorizerAccessToken = authorizerAccessToken; - } - - public int getExpiresIn() { - return expiresIn; - } - - public void setExpiresIn(int expiresIn) { - this.expiresIn = expiresIn; - } } diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/util/json/WxOpenAuthorizerAccessTokenGsonAdapter.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/util/json/WxOpenAuthorizerAccessTokenGsonAdapter.java index 82a04b9ba8..6932d25736 100644 --- a/weixin-java-open/src/main/java/me/chanjar/weixin/open/util/json/WxOpenAuthorizerAccessTokenGsonAdapter.java +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/util/json/WxOpenAuthorizerAccessTokenGsonAdapter.java @@ -15,6 +15,7 @@ public WxOpenAuthorizerAccessToken deserialize(JsonElement jsonElement, Type typ WxOpenAuthorizerAccessToken authorizerAccessToken = new WxOpenAuthorizerAccessToken(); JsonObject jsonObject = jsonElement.getAsJsonObject(); authorizerAccessToken.setAuthorizerAccessToken(GsonHelper.getString(jsonObject, "authorizer_access_token")); + authorizerAccessToken.setAuthorizerRefreshToken(GsonHelper.getString(jsonObject, "authorizer_refresh_token")); authorizerAccessToken.setExpiresIn(GsonHelper.getPrimitiveInteger(jsonObject, "expires_in")); return authorizerAccessToken; }