From 6554500a5bdda047f358a4c671b9901743a051ac Mon Sep 17 00:00:00 2001 From: iluyuns <107970857+iluyuns@users.noreply.github.com> Date: Wed, 21 Feb 2024 20:05:35 +0800 Subject: [PATCH] Update oauth.md (#2790) Scope considerations --- docs/src/5.x/official-account/oauth.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/src/5.x/official-account/oauth.md b/docs/src/5.x/official-account/oauth.md index f4a35b4a6..673d7fce5 100755 --- a/docs/src/5.x/official-account/oauth.md +++ b/docs/src/5.x/official-account/oauth.md @@ -176,10 +176,11 @@ $config = [ $app = Factory::officialAccount($config); $oauth = $app->oauth; - // 获取 OAuth 授权结果用户信息 $code = "微信回调URL携带的 code"; -$user = $oauth->userFromCode($code); +// 不少用户这里的 code 是来源于静默授权 如果这里你的 $oauth 没有配置 scopes 为 snsapi_base 调用 $oauth->userFromCode($code); 默认会走 snsapi_userinfo; +$oauth = $app->oauth->scopes(['snsapi_base']) +$user = $oauth->userFromCode($code); $_SESSION['wechat_user'] = $user->toArray();