From 14dd2b617937d7483a553c8763a703e09f637d2e Mon Sep 17 00:00:00 2001 From: "yadong.zhang" Date: Sun, 3 Dec 2023 20:17:47 +0800 Subject: [PATCH] =?UTF-8?q?:hankey:=20=E4=BF=AE=E5=A4=8D=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E5=85=AC=E4=BC=97=E5=B9=B3=E5=8F=B0=20scope=20=E4=B8=BA=20snsa?= =?UTF-8?q?pi=5Fbase=20=E7=99=BB=E5=BD=95=E6=8A=A5=E9=94=99=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20[181](https://github.com/justauth/JustAuth?= =?UTF-8?q?/issues/181)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../oauth/request/AuthWeChatMpRequest.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/java/me/zhyd/oauth/request/AuthWeChatMpRequest.java b/src/main/java/me/zhyd/oauth/request/AuthWeChatMpRequest.java index 5ee1374..8ade04c 100644 --- a/src/main/java/me/zhyd/oauth/request/AuthWeChatMpRequest.java +++ b/src/main/java/me/zhyd/oauth/request/AuthWeChatMpRequest.java @@ -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.*; /** * 微信公众平台登录 @@ -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"))