Skip to content

Commit

Permalink
💩 修复微信公众平台 scope 为 snsapi_base 登录报错的问题 [181](#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangyd-c committed Dec 3, 2023
1 parent d6ba3bb commit 14dd2b6
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/main/java/me/zhyd/oauth/request/AuthWeChatMpRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
import me.zhyd.oauth.model.AuthResponse;
import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.utils.AuthScopeUtils;
import me.zhyd.oauth.utils.GlobalAuthUtils;
import me.zhyd.oauth.utils.HttpUtils;
import me.zhyd.oauth.utils.UrlBuilder;
import me.zhyd.oauth.utils.*;

/**
* 微信公众平台登录
Expand Down Expand Up @@ -47,17 +44,26 @@ protected AuthToken getAccessToken(AuthCallback authCallback) {
protected AuthUser getUserInfo(AuthToken authToken) {
String openId = authToken.getOpenId();

String scope = authToken.getScope();
if (!StringUtils.isEmpty(scope) && !scope.contains("snsapi_userinfo")) {
return AuthUser.builder()
.rawUserInfo(JSONObject.parseObject(JSONObject.toJSONString(authToken)))
.uuid(openId)
.snapshotUser(authToken.isSnapshotUser())
.token(authToken)
.source(source.toString())
.build();
}

String response = doGetUserInfo(authToken);
JSONObject object = JSONObject.parseObject(response);

this.checkResponse(object);

String location = String.format("%s-%s-%s", object.getString("country"), object.getString("province"), object.getString("city"));

if (object.containsKey("unionid")) {
authToken.setUnionId(object.getString("unionid"));
}

return AuthUser.builder()
.rawUserInfo(object)
.username(object.getString("nickname"))
Expand Down

0 comments on commit 14dd2b6

Please sign in to comment.