From c34e226a541ed92c1a8f93e73befd27ce3cc7c31 Mon Sep 17 00:00:00 2001 From: "yadong.zhang" Date: Sun, 7 Jun 2020 16:30:28 +0800 Subject: [PATCH] =?UTF-8?q?:twisted=5Frightwards=5Farrows:=20=E5=90=88?= =?UTF-8?q?=E5=B9=B6=20Gitee=20PR=20!15?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../zhyd/oauth/request/AuthRenrenRequest.java | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/main/java/me/zhyd/oauth/request/AuthRenrenRequest.java b/src/main/java/me/zhyd/oauth/request/AuthRenrenRequest.java index 69fa251..55d7d81 100644 --- a/src/main/java/me/zhyd/oauth/request/AuthRenrenRequest.java +++ b/src/main/java/me/zhyd/oauth/request/AuthRenrenRequest.java @@ -2,7 +2,7 @@ package me.zhyd.oauth.request; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; -import me.zhyd.oauth.utils.HttpUtils; +import com.xkcoding.http.util.UrlUtil; import me.zhyd.oauth.cache.AuthStateCache; import me.zhyd.oauth.config.AuthConfig; import me.zhyd.oauth.enums.AuthUserGender; @@ -11,10 +11,9 @@ 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.HttpUtils; import me.zhyd.oauth.utils.UrlBuilder; -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; import java.util.Objects; import static me.zhyd.oauth.config.AuthDefaultSource.RENREN; @@ -72,17 +71,13 @@ public class AuthRenrenRequest extends AuthDefaultRequest { throw new AuthException("Failed to get token from Renren: " + jsonObject); } - try { - return AuthToken.builder() - .tokenType(jsonObject.getString("token_type")) - .expireIn(jsonObject.getIntValue("expires_in")) - .accessToken(URLEncoder.encode(jsonObject.getString("access_token"), "UTF-8")) - .refreshToken(URLEncoder.encode(jsonObject.getString("refresh_token"), "UTF-8")) - .openId(jsonObject.getJSONObject("user").getString("id")) - .build(); - } catch (UnsupportedEncodingException e) { - throw new AuthException("Failed to encode token" + e.getMessage()); - } + return AuthToken.builder() + .tokenType(jsonObject.getString("token_type")) + .expireIn(jsonObject.getIntValue("expires_in")) + .accessToken(UrlUtil.urlEncode(jsonObject.getString("access_token"))) + .refreshToken(UrlUtil.urlEncode(jsonObject.getString("refresh_token"))) + .openId(jsonObject.getJSONObject("user").getString("id")) + .build(); } private String getAvatarUrl(JSONObject userObj) {