提交 1c1d2dc9 编写于 作者: 智布道's avatar 智布道 👁 提交者: Gitee

!2 修复最近提出一些问题和BUG

Merge pull request !2 from skqing/master
......@@ -69,12 +69,16 @@ public class AuthAlipayRequest extends BaseAuthRequest {
}
String province = response.getProvince(),
city = response.getCity();
String location = province;
if (!StringUtils.isEmpty(city)) {
location = location + "-"+city;
}
return AuthUser.builder()
.uuid(response.getUserId())
.username(StringUtils.isEmpty(response.getUserName()) ? response.getNickName() : response.getUserName())
.nickname(response.getNickName())
.avatar(response.getAvatar())
.location(String.format("%s %s", StringUtils.isEmpty(province) ? "" : province, StringUtils.isEmpty(city) ? "" : city))
.location(location)
.gender(AuthUserGender.getRealGender(response.getGender()))
.token(authToken)
.source(AuthSource.ALIPAY)
......
......@@ -6,10 +6,7 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthDingTalkErrorCode;
import me.zhyd.oauth.model.AuthSource;
import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.model.*;
import me.zhyd.oauth.utils.GlobalAuthUtil;
import me.zhyd.oauth.utils.UrlBuilder;
......@@ -58,6 +55,7 @@ public class AuthDingTalkRequest extends BaseAuthRequest {
.uuid(object.getString("unionid"))
.nickname(object.getString("nick"))
.username(object.getString("nick"))
.gender(AuthUserGender.UNKNOW)
.source(AuthSource.DINGTALK)
.token(token)
.build();
......
......@@ -5,10 +5,7 @@ import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONObject;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthResponse;
import me.zhyd.oauth.model.AuthSource;
import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.model.*;
import me.zhyd.oauth.utils.UrlBuilder;
......@@ -45,6 +42,7 @@ public class AuthDouyinRequest extends BaseAuthRequest {
.username(userInfoObject.getString("nickname"))
.nickname(userInfoObject.getString("nickname"))
.avatar(userInfoObject.getString("avatar"))
.gender(AuthUserGender.UNKNOW)
.token(authToken)
.source(AuthSource.DOUYIN)
.build();
......
......@@ -6,10 +6,7 @@ import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONObject;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthResponse;
import me.zhyd.oauth.model.AuthSource;
import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.model.*;
import me.zhyd.oauth.utils.UrlBuilder;
import java.text.MessageFormat;
......@@ -74,6 +71,7 @@ public class AuthMiRequest extends BaseAuthRequest {
.nickname(user.getString("miliaoNick"))
.avatar(user.getString("miliaoIcon"))
.email(user.getString("mail"))
.gender(AuthUserGender.UNKNOW)
.token(authToken)
.source(AuthSource.MI)
.build();
......
......@@ -48,8 +48,15 @@ public class AuthQqRequest extends BaseAuthRequest {
@Override
protected AuthUser getUserInfo(AuthToken authToken) {
String accessToken = authToken.getAccessToken();
String openId = this.getOpenId(accessToken);
HttpResponse response = HttpRequest.get(UrlBuilder.getQqUserInfoUrl(config.getClientId(), accessToken, openId))
String openIdStr = this.getOpenId(accessToken);
String[] openIdArr = openIdStr.split("\\|");
authToken.setOpenId(openIdArr[0]);
String uuid = authToken.getOpenId();
if (openIdArr.length == 2) {
uuid = openIdArr[1];
}
HttpResponse response = HttpRequest.get(UrlBuilder.getQqUserInfoUrl(config.getClientId(), accessToken, authToken.getOpenId()))
.execute();
JSONObject object = JSONObject.parseObject(response.body());
if (object.getIntValue("ret") != 0) {
......@@ -64,7 +71,7 @@ public class AuthQqRequest extends BaseAuthRequest {
.nickname(object.getString("nickname"))
.avatar(avatar)
.location(object.getString("province") + "-" + object.getString("city"))
.uuid(openId)
.uuid(uuid)
.gender(AuthUserGender.getRealGender(object.getString("gender")))
.token(authToken)
.source(AuthSource.QQ)
......@@ -78,13 +85,21 @@ public class AuthQqRequest extends BaseAuthRequest {
String body = response.body();
String removePrefix = StrUtil.replace(body, "callback(", "");
String removeSuffix = StrUtil.replace(removePrefix, ");", "");
String openId = StrUtil.trim(removeSuffix);
JSONObject object = JSONObject.parseObject(openId);
String jsonStr = StrUtil.trim(removeSuffix);
JSONObject object = JSONObject.parseObject(jsonStr);
StringBuffer sb = new StringBuffer();
if (object.containsKey("openid")) {
return object.getString("openid");
}
sb.append(object.getString("openid"));
sb.append("|");
} else {
throw new AuthException("Invalid openId");
}
throw new AuthException("Invalid openId");
if (object.containsKey("unionid")) {
sb.append(object.getString("unionid"));
}
return sb.toString();
}
throw new AuthException("request error");
}
}
......@@ -58,7 +58,7 @@ public class UrlBuilder {
private static final String QQ_ACCESS_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&grant_type=authorization_code&code={3}&redirect_uri={4}";
private static final String QQ_USER_INFO_PATTERN = "{0}?oauth_consumer_key={1}&access_token={2}&openid={3}";
private static final String QQ_AUTHORIZE_PATTERN = "{0}?client_id={1}&response_type=code&redirect_uri={2}&state={3}";
private static final String QQ_OPENID_PATTERN = "{0}?access_token={1}";
private static final String QQ_OPENID_PATTERN = "{0}?access_token={1}&unionid=1";
private static final String WECHAT_AUTHORIZE_PATTERN = "{0}?appid={1}&redirect_uri={2}&response_type=code&scope=snsapi_login&state={3}#wechat_redirect";
private static final String WECHAT_ACCESS_TOKEN_PATTERN = "{0}?appid={1}&secret={2}&code={3}&grant_type=authorization_code";
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册