缓存用户绑定请求参数、提供任务列表使用

This commit is contained in:
2025-06-16 19:26:15 +08:00
parent 1e6816f802
commit 6c2ef9dfe2
17 changed files with 180 additions and 243 deletions

View File

@ -4,11 +4,6 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/go-resty/resty/v2"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/glog"
"github.com/gogf/gf/v2/util/gconv"
"github.com/gogf/gf/v2/util/grand"
"net/url"
"server/internal/consts"
"server/internal/model"
@ -16,6 +11,12 @@ import (
"server/utility/encrypt"
"server/utility/rsa"
"time"
"github.com/go-resty/resty/v2"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/glog"
"github.com/gogf/gf/v2/util/gconv"
"github.com/gogf/gf/v2/util/grand"
)
type gamelifeClient struct {
@ -168,7 +169,8 @@ func (s *gamelifeClient) GetUrl(ctx context.Context, popenid, appname, nickname
rooturl = s.unBoundUrlMap[s.Mode]
}
cacheData, err := g.Redis().Get(ctx, fmt.Sprintf(consts.GameLifeUserKey, popenid))
gamelifeCacheKey := fmt.Sprintf(consts.GameLifeUserKey, popenid)
cacheData, err := g.Redis().Get(ctx, gamelifeCacheKey)
if err != nil {
return "", ecode.Fail.Sub("从缓存中获取用户信息失败")
}
@ -226,7 +228,15 @@ func (s *gamelifeClient) GetUrl(ctx context.Context, popenid, appname, nickname
}
// 将请求参数更新到缓存中
gamelifeCache.Params = queryParams.Encode()
// 获取原缓存值、过期时间
ttl, err := g.Redis().TTL(ctx, gamelifeCacheKey)
if err != nil {
return "", ecode.Fail.Sub("获取缓存过期时间失败")
}
// 更新数据
if err = g.Redis().SetEX(ctx, gamelifeCacheKey, gamelifeCache, ttl); err != nil {
return "", ecode.Fail.Sub("更新缓存失败")
}
// 拼接最终 URL
url := fmt.Sprintf("%s?%s", rooturl, queryParams.Encode())
return url, nil