1
0
mirror of synced 2025-12-27 01:48:11 +08:00

🍻 醉酒写代码

This commit is contained in:
yadong.zhang
2019-06-18 19:51:53 +08:00
parent c0dd700b0a
commit 42ede32fc5
2 changed files with 9 additions and 5 deletions

View File

@@ -19,6 +19,7 @@ public class AuthToken {
private String uid;
private String openId;
private String accessCode;
private String unionId;
/**
* Google附带属性

View File

@@ -48,7 +48,7 @@ public class AuthQqRequest extends BaseAuthRequest {
@Override
protected AuthUser getUserInfo(AuthToken authToken) {
String accessToken = authToken.getAccessToken();
String openId = this.getOpenId(accessToken);
String openId = this.getOpenId(authToken);
HttpResponse response = HttpRequest.get(UrlBuilder.getQqUserInfoUrl(config.getClientId(), accessToken, openId))
.execute();
JSONObject object = JSONObject.parseObject(response.body());
@@ -73,7 +73,8 @@ public class AuthQqRequest extends BaseAuthRequest {
.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))
.execute();
if (response.isOk()) {
@@ -82,10 +83,12 @@ public class AuthQqRequest extends BaseAuthRequest {
String removeSuffix = StrUtil.replace(removePrefix, ");", "");
String openId = StrUtil.trim(removeSuffix);
JSONObject object = JSONObject.parseObject(openId);
if (object.containsKey("openid")) {
return object.getString("openid");
if (object.containsKey("error")) {
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");
}