package payment import ( "context" "fmt" ) // GetUidFromCtx 从context中获取用户ID func GetUidFromCtx(ctx context.Context) (string, error) { userID := ctx.Value("user_id") if userID == nil { return "", fmt.Errorf("用户ID不存在于上下文中") } id, ok := userID.(string) if !ok { return "", fmt.Errorf("用户ID类型错误") } if id == "" { return "", fmt.Errorf("用户ID为空") } return id, nil }