提交 525c406c 编写于 作者: 智布道's avatar 智布道 👁

🐛 修复抖音登录取值取错层级的问题(issue#I15SIG@Gitee)

上级 e65d87da
...@@ -67,7 +67,7 @@ ...@@ -67,7 +67,7 @@
- 网站B:可以理解成 Oschina - 网站B:可以理解成 Oschina
- 第三方C:可以理解成 Github - 第三方C:可以理解成 Github
需求:你想通过Github第三方登录Oschina 需求:你想通过Github第三方登录Oschina。(_注:下面的内容为流程图,如果您在阅读的时候显示为纯文字,请刷新页面_)
<div class="mermaid"> <div class="mermaid">
sequenceDiagram sequenceDiagram
......
...@@ -94,10 +94,15 @@ public abstract class AuthDefaultRequest implements AuthRequest { ...@@ -94,10 +94,15 @@ public abstract class AuthDefaultRequest implements AuthRequest {
*/ */
private AuthResponse responseError(Exception e) { private AuthResponse responseError(Exception e) {
int errorCode = AuthResponseStatus.FAILURE.getCode(); int errorCode = AuthResponseStatus.FAILURE.getCode();
String errorMsg = e.getMessage();
if (e instanceof AuthException) { if (e instanceof AuthException) {
errorCode = ((AuthException) e).getErrorCode(); AuthException authException = ((AuthException) e);
errorCode = authException.getErrorCode();
if (StringUtils.isNotEmpty(authException.getErrorMsg())) {
errorMsg = authException.getErrorMsg();
} }
return AuthResponse.builder().code(errorCode).msg(e.getMessage()).build(); }
return AuthResponse.builder().code(errorCode).msg(errorMsg).build();
} }
/** /**
......
...@@ -42,13 +42,15 @@ public class AuthDouyinRequest extends AuthDefaultRequest { ...@@ -42,13 +42,15 @@ public class AuthDouyinRequest extends AuthDefaultRequest {
HttpResponse response = doGetUserInfo(authToken); HttpResponse response = doGetUserInfo(authToken);
JSONObject userInfoObject = JSONObject.parseObject(response.body()); JSONObject userInfoObject = JSONObject.parseObject(response.body());
this.checkResponse(userInfoObject); this.checkResponse(userInfoObject);
JSONObject dataObj = userInfoObject.getJSONObject("data");
return AuthUser.builder() return AuthUser.builder()
.uuid(userInfoObject.getString("union_id")) .uuid(dataObj.getString("union_id"))
.username(userInfoObject.getString("nickname")) .username(dataObj.getString("nickname"))
.nickname(userInfoObject.getString("nickname")) .nickname(dataObj.getString("nickname"))
.avatar(userInfoObject.getString("avatar")) .avatar(dataObj.getString("avatar"))
.remark(userInfoObject.getString("description")) .remark(dataObj.getString("description"))
.gender(AuthUserGender.UNKNOWN) .gender(AuthUserGender.getRealGender(dataObj.getString("gender")))
.location(String.format("%s %s %s", dataObj.getString("country"), dataObj.getString("province"), dataObj.getString("city")))
.token(authToken) .token(authToken)
.source(source.toString()) .source(source.toString())
.build(); .build();
...@@ -87,12 +89,13 @@ public class AuthDouyinRequest extends AuthDefaultRequest { ...@@ -87,12 +89,13 @@ public class AuthDouyinRequest extends AuthDefaultRequest {
String accessTokenStr = response.body(); String accessTokenStr = response.body();
JSONObject object = JSONObject.parseObject(accessTokenStr); JSONObject object = JSONObject.parseObject(accessTokenStr);
this.checkResponse(object); this.checkResponse(object);
JSONObject dataObj = object.getJSONObject("data");
return AuthToken.builder() return AuthToken.builder()
.accessToken(object.getString("access_token")) .accessToken(dataObj.getString("access_token"))
.openId(object.getString("open_id")) .openId(dataObj.getString("open_id"))
.expireIn(object.getIntValue("expires_in")) .expireIn(dataObj.getIntValue("expires_in"))
.refreshToken(object.getString("refresh_token")) .refreshToken(dataObj.getString("refresh_token"))
.scope(object.getString("scope")) .scope(dataObj.getString("scope"))
.build(); .build();
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册