1.修改basedo字段类型

2、提供获取authen中用户信息的方法
This commit is contained in:
2025-12-02 09:07:21 +08:00
parent 8ed282877e
commit cd3571554f
3 changed files with 34 additions and 4 deletions

View File

@@ -1,9 +1,15 @@
package utils
import (
"context"
"fmt"
"gitee.com/red-future---jilin-g/common/do"
"github.com/gogf/gf/v2/database/gredis"
"github.com/gogf/gf/v2/errors/gcode"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/util/gconv"
"github.com/tiger1103/gfast-token/gftoken"
"reflect"
"time"
)
@@ -51,3 +57,20 @@ func GetMonthToday(t time.Time, month int) time.Time {
}
return target.AddDate(0, 0, t.Day()-1)
}
func GetUserInfo(ctx context.Context) (user do.User, err error) {
redisAddr := g.Cfg().MustGet(ctx, "redis.default.address").String()
gft := gftoken.NewGfToken(
gftoken.WithCacheKey("gfToken:"),
gftoken.WithTimeout(20),
gftoken.WithMaxRefresh(10),
gftoken.WithMultiLogin(true),
//gftoken.WithExcludePaths(g.SliceStr{"/excludeDemo"}),
gftoken.WithGRedisConfig(&gredis.Config{
Address: redisAddr,
Db: 1,
}))
data, _ := gft.ParseToken(g.RequestFromCtx(ctx))
user.Id = gconv.Map(data.Data)["id"]
user.TenantId = gconv.Map(data.Data)["tenantId"]
return
}