三端用户手机号联通,增加临时用户

This commit is contained in:
2025-06-17 23:46:37 +08:00
parent b98ad2af2c
commit f1f0c5dbd2
58 changed files with 1540 additions and 1252 deletions

View File

@@ -2,11 +2,8 @@ package middleware
import (
"context"
"encoding/json"
"fmt"
"net/http"
"qnc-server/app/main/api/internal/config"
"qnc-server/common/ctxdata"
jwtx "qnc-server/common/jwt"
"qnc-server/common/xerr"
@@ -41,17 +38,14 @@ func (m *AuthInterceptorMiddleware) Handle(next http.HandlerFunc) http.HandlerFu
}
// 解析JWT令牌
userId, err := jwtx.ParseJwtToken(authHeader, m.Config.JwtAuth.AccessSecret)
claims, err := jwtx.ParseJwtToken(authHeader, m.Config.JwtAuth.AccessSecret)
if err != nil {
// JWT解析失败返回401错误
httpx.Error(w, errors.Wrapf(xerr.NewErrCode(ErrCodeUnauthorized), "token解析失败: %v", err))
return
}
// 将用户ID转换为json.Number类型后添加到请求上下文
userIdStr := fmt.Sprintf("%d", userId)
userIdJsonNum := json.Number(userIdStr)
ctx := context.WithValue(r.Context(), ctxdata.CtxKeyJwtUserId, userIdJsonNum)
ctx := context.WithValue(r.Context(), jwtx.ExtraKey, claims)
// 使用新的上下文继续处理请求
next(w, r.WithContext(ctx))