From f2e596f6eccc37fc6e960bcf6a004e66e50e8967 Mon Sep 17 00:00:00 2001 From: QTom Date: Thu, 2 Apr 2026 20:43:56 +0800 Subject: [PATCH] =?UTF-8?q?fix(oauth):=20=E6=AF=8F=E6=AC=A1=E5=88=B7?= =?UTF-8?q?=E6=96=B0=E9=83=BD=E9=80=9A=E8=BF=87=20backend-api=20=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E6=9C=80=E6=96=B0=20plan=5Ftype?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 账号订阅类型可能每月变化,id_token 中的 plan_type 是签发时的快照, 不一定反映当前状态。移除 plan_type == "" 前置条件,确保每次刷新都 调用 ChatGPT backend-api 获取实时订阅类型并覆盖旧值。 Co-Authored-By: Claude Opus 4.6 (1M context) --- backend/internal/service/openai_oauth_service.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/backend/internal/service/openai_oauth_service.go b/backend/internal/service/openai_oauth_service.go index 0f004b01..5c071168 100644 --- a/backend/internal/service/openai_oauth_service.go +++ b/backend/internal/service/openai_oauth_service.go @@ -259,8 +259,9 @@ func (s *OpenAIOAuthService) RefreshTokenWithClientID(ctx context.Context, refre tokenInfo.PlanType = userInfo.PlanType } - // id_token 中缺少 plan_type 时(如 Mobile RT),尝试通过 ChatGPT backend-api 补全 - if tokenInfo.PlanType == "" && tokenInfo.AccessToken != "" && s.privacyClientFactory != nil { + // 每次刷新都通过 ChatGPT backend-api 获取最新的 plan_type, + // 因为账号订阅类型可能每月变化,id_token 中的值是签发时的快照,不一定反映当前状态。 + if tokenInfo.AccessToken != "" && s.privacyClientFactory != nil { // 从 access_token JWT 中提取 orgID(poid),用于匹配正确的账号 orgID := tokenInfo.OrganizationID if orgID == "" { @@ -269,7 +270,7 @@ func (s *OpenAIOAuthService) RefreshTokenWithClientID(ctx context.Context, refre } } if info := fetchChatGPTAccountInfo(ctx, s.privacyClientFactory, tokenInfo.AccessToken, proxyURL, orgID); info != nil { - if tokenInfo.PlanType == "" && info.PlanType != "" { + if info.PlanType != "" { tokenInfo.PlanType = info.PlanType } if tokenInfo.Email == "" && info.Email != "" {