From 179287f7208b42af53a3f44661d60e8705c1ca6a Mon Sep 17 00:00:00 2001 From: "yadong.zhang" Date: Sun, 28 Jun 2020 22:08:31 +0800 Subject: [PATCH] =?UTF-8?q?:alien:=20=E5=A2=9E=E5=8A=A0=E9=98=BF=E9=87=8C?= =?UTF-8?q?=E4=BA=91=E6=8E=88=E6=9D=83=E7=99=BB=E5=BD=95=E4=B8=AD=E5=88=B7?= =?UTF-8?q?=E6=96=B0=E6=8E=88=E6=9D=83token=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../zhyd/oauth/request/AuthAlipayRequest.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/main/java/me/zhyd/oauth/request/AuthAlipayRequest.java b/src/main/java/me/zhyd/oauth/request/AuthAlipayRequest.java index c47b6dc..5d615ee 100644 --- a/src/main/java/me/zhyd/oauth/request/AuthAlipayRequest.java +++ b/src/main/java/me/zhyd/oauth/request/AuthAlipayRequest.java @@ -11,9 +11,11 @@ import com.alipay.api.response.AlipayUserInfoShareResponse; import me.zhyd.oauth.cache.AuthStateCache; import me.zhyd.oauth.config.AuthConfig; import me.zhyd.oauth.config.AuthDefaultSource; +import me.zhyd.oauth.enums.AuthResponseStatus; import me.zhyd.oauth.enums.AuthUserGender; import me.zhyd.oauth.exception.AuthException; import me.zhyd.oauth.model.AuthCallback; +import me.zhyd.oauth.model.AuthResponse; import me.zhyd.oauth.model.AuthToken; import me.zhyd.oauth.model.AuthUser; import me.zhyd.oauth.utils.StringUtils; @@ -63,6 +65,37 @@ public class AuthAlipayRequest extends AuthDefaultRequest { .build(); } + /** + * 刷新access token (续期) + * + * @param authToken 登录成功后返回的Token信息 + * @return AuthResponse + */ + @Override + public AuthResponse refresh(AuthToken authToken) { + AlipaySystemOauthTokenRequest request = new AlipaySystemOauthTokenRequest(); + request.setGrantType("refresh_token"); + request.setRefreshToken(authToken.getRefreshToken()); + AlipaySystemOauthTokenResponse response = null; + try { + response = this.alipayClient.execute(request); + } catch (Exception e) { + throw new AuthException(e); + } + if (!response.isSuccess()) { + throw new AuthException(response.getSubMsg()); + } + return AuthResponse.builder() + .code(AuthResponseStatus.SUCCESS.getCode()) + .data(AuthToken.builder() + .accessToken(response.getAccessToken()) + .uid(response.getUserId()) + .expireIn(Integer.parseInt(response.getExpiresIn())) + .refreshToken(response.getRefreshToken()) + .build()) + .build(); + } + @Override protected AuthUser getUserInfo(AuthToken authToken) { String accessToken = authToken.getAccessToken(); -- GitLab