From c0b64c9e30c4e56bfd31c6a027d32451c72b5429 Mon Sep 17 00:00:00 2001 From: huang Date: Tue, 14 Apr 2026 11:09:42 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=99=BB=E5=BD=95=E6=97=B6=E5=B0=86?= =?UTF-8?q?=E4=B8=BB=E6=89=8B=E6=9C=BA=E5=8F=B7=E5=86=99=E5=85=A5=20JWT?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E5=A4=8D=20bound=5Fphone=20=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E7=A9=BA=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/service/client_auth/service.go | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/internal/service/client_auth/service.go b/internal/service/client_auth/service.go index 39495af..cfdcc5a 100644 --- a/internal/service/client_auth/service.go +++ b/internal/service/client_auth/service.go @@ -692,7 +692,19 @@ func (s *Service) markAssetAsSold(ctx context.Context, tx *gorm.DB, assetType st } func (s *Service) issueLoginToken(ctx context.Context, customerID uint) (string, bool, error) { - token, err := s.jwtManager.GeneratePersonalCustomerToken(customerID, "") + // 查询用户已绑定的主手机号,写入 JWT,供后续接口直接从 context 取用 + var boundPhone string + needBindPhone := false + primaryPhone, phoneErr := s.phoneStore.GetPrimaryPhone(ctx, customerID) + if phoneErr == nil { + boundPhone = primaryPhone.Phone + } else if phoneErr != gorm.ErrRecordNotFound { + return "", false, errors.Wrap(errors.CodeInternalError, phoneErr, "查询手机号绑定关系失败") + } else if viper.GetBool("client.require_phone_binding") { + needBindPhone = true + } + + token, err := s.jwtManager.GeneratePersonalCustomerToken(customerID, boundPhone) if err != nil { return "", false, errors.Wrap(errors.CodeInternalError, err, "生成登录令牌失败") } @@ -712,15 +724,6 @@ func (s *Service) issueLoginToken(ctx context.Context, customerID uint) (string, return "", false, errors.Wrap(errors.CodeRedisError, err, "保存登录状态失败") } - needBindPhone := false - if viper.GetBool("client.require_phone_binding") { - if _, err := s.phoneStore.GetPrimaryPhone(ctx, customerID); err == gorm.ErrRecordNotFound { - needBindPhone = true - } else if err != nil { - return "", false, errors.Wrap(errors.CodeInternalError, err, "查询手机号绑定关系失败") - } - } - return token, needBindPhone, nil }