提交 42ede32f 编写于 作者: 智布道's avatar 智布道 👁

🍻 醉酒写代码

上级 c0dd700b
...@@ -19,6 +19,7 @@ public class AuthToken { ...@@ -19,6 +19,7 @@ public class AuthToken {
private String uid; private String uid;
private String openId; private String openId;
private String accessCode; private String accessCode;
private String unionId;
/** /**
* Google附带属性 * Google附带属性
......
...@@ -48,7 +48,7 @@ public class AuthQqRequest extends BaseAuthRequest { ...@@ -48,7 +48,7 @@ public class AuthQqRequest extends BaseAuthRequest {
@Override @Override
protected AuthUser getUserInfo(AuthToken authToken) { protected AuthUser getUserInfo(AuthToken authToken) {
String accessToken = authToken.getAccessToken(); String accessToken = authToken.getAccessToken();
String openId = this.getOpenId(accessToken); String openId = this.getOpenId(authToken);
HttpResponse response = HttpRequest.get(UrlBuilder.getQqUserInfoUrl(config.getClientId(), accessToken, openId)) HttpResponse response = HttpRequest.get(UrlBuilder.getQqUserInfoUrl(config.getClientId(), accessToken, openId))
.execute(); .execute();
JSONObject object = JSONObject.parseObject(response.body()); JSONObject object = JSONObject.parseObject(response.body());
...@@ -73,7 +73,8 @@ public class AuthQqRequest extends BaseAuthRequest { ...@@ -73,7 +73,8 @@ public class AuthQqRequest extends BaseAuthRequest {
.build(); .build();
} }
private String getOpenId(String accessToken) { private String getOpenId(AuthToken authToken) {
String accessToken = authToken.getAccessToken();
HttpResponse response = HttpRequest.get(UrlBuilder.getQqOpenidUrl("https://graph.qq.com/oauth2.0/me", accessToken)) HttpResponse response = HttpRequest.get(UrlBuilder.getQqOpenidUrl("https://graph.qq.com/oauth2.0/me", accessToken))
.execute(); .execute();
if (response.isOk()) { if (response.isOk()) {
...@@ -82,10 +83,12 @@ public class AuthQqRequest extends BaseAuthRequest { ...@@ -82,10 +83,12 @@ public class AuthQqRequest extends BaseAuthRequest {
String removeSuffix = StrUtil.replace(removePrefix, ");", ""); String removeSuffix = StrUtil.replace(removePrefix, ");", "");
String openId = StrUtil.trim(removeSuffix); String openId = StrUtil.trim(removeSuffix);
JSONObject object = JSONObject.parseObject(openId); JSONObject object = JSONObject.parseObject(openId);
if (object.containsKey("openid")) { if (object.containsKey("error")) {
return object.getString("openid"); throw new AuthException(object.get("error") + ":" + object.get("error_description"));
} }
throw new AuthException("Invalid openId"); authToken.setOpenId(object.getString("openid"));
authToken.setUnionId(object.getString("unionid"));
return authToken.getOpenId();
} }
throw new AuthException("Invalid openId"); throw new AuthException("Invalid openId");
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册