修改微信扫码登录 access_token 问题

This commit is contained in:
2025-06-23 11:42:08 +08:00
parent 33b040065f
commit 03c7939a81
13 changed files with 346 additions and 60 deletions

View File

@ -178,7 +178,7 @@ func (s *gamelifeClient) GetUrl(ctx context.Context, popenID, appName, nickname
if !isBound {
rootURL = s.unBoundURLMap[s.config.Mode]
}
cache, err := s.ensureUserCacheWithParams(ctx, popenID, appName, nickname, bindType)
cache, err := s.ensureUserCacheWithParams(ctx, popenID, appName, nickname, bindType, isBound)
if err != nil {
return "", err
}
@ -319,7 +319,7 @@ func (s *gamelifeClient) RequestActivity(ctx context.Context, in *model.QQNetbar
if err != nil {
return nil, ecode.Fail.Sub("获取游戏编码失败")
}
cache, err := s.ensureUserCacheWithParams(ctx, in.PopenId, value.String(), in.NickName, in.BindType)
cache, err := s.ensureUserCacheWithParams(ctx, in.PopenId, value.String(), in.NickName, in.BindType, true)
in.TaskParam.BrandId = s.config.BrandID
var result model.GameTaskResponse
resp, err := client.R().
@ -332,11 +332,11 @@ func (s *gamelifeClient) RequestActivity(ctx context.Context, in *model.QQNetbar
}
return &result, nil
case consts.QueryUserRoleList:
value, err := dao.Games.Ctx(ctx).Where(do.Games{GameId: in.QueryUserGoodsDetailParam.Gid}).Fields(dao.Games.Columns().GameCode).Value()
value, err := dao.Games.Ctx(ctx).Where(do.Games{GameId: in.UserRoleParam.Gid}).Fields(dao.Games.Columns().GameCode).Value()
if err != nil {
return nil, ecode.Fail.Sub("获取游戏编码失败")
}
cache, err := s.ensureUserCacheWithParams(ctx, in.PopenId, value.String(), in.NickName, in.BindType)
cache, err := s.ensureUserCacheWithParams(ctx, in.PopenId, value.String(), in.NickName, in.BindType, true)
var result model.UserRoleListResponse
resp, err := client.R().
SetContext(ctx).
@ -346,13 +346,14 @@ func (s *gamelifeClient) RequestActivity(ctx context.Context, in *model.QQNetbar
if err != nil || resp.IsError() {
return nil, ecode.Fail.Sub("请求出现异常")
}
return &result.RoleList, nil
case consts.GetGift:
value, err := dao.Games.Ctx(ctx).Where(do.Games{GameId: in.QueryUserGoodsDetailParam.Gid}).Fields(dao.Games.Columns().GameCode).Value()
if err != nil {
return nil, ecode.Fail.Sub("获取游戏编码失败")
}
cache, err := s.ensureUserCacheWithParams(ctx, in.PopenId, value.String(), in.NickName, in.BindType)
cache, err := s.ensureUserCacheWithParams(ctx, in.PopenId, value.String(), in.NickName, in.BindType, true)
var result model.GiftResponse
resp, err := client.R().
SetContext(ctx).
@ -368,7 +369,7 @@ func (s *gamelifeClient) RequestActivity(ctx context.Context, in *model.QQNetbar
if err != nil {
return nil, ecode.Fail.Sub("获取游戏编码失败")
}
cache, err := s.ensureUserCacheWithParams(ctx, in.PopenId, value.String(), in.NickName, in.BindType)
cache, err := s.ensureUserCacheWithParams(ctx, in.PopenId, value.String(), in.NickName, in.BindType, true)
var result model.GoodsResponse
resp, err := client.R().
SetContext(ctx).
@ -384,7 +385,7 @@ func (s *gamelifeClient) RequestActivity(ctx context.Context, in *model.QQNetbar
if err != nil {
return nil, ecode.Fail.Sub("获取游戏编码失败")
}
cache, err := s.ensureUserCacheWithParams(ctx, in.PopenId, value.String(), in.NickName, in.BindType)
cache, err := s.ensureUserCacheWithParams(ctx, in.PopenId, value.String(), in.NickName, in.BindType, true)
var result model.ExchangeGoodsResponse
resp, err := client.R().
SetContext(ctx).
@ -400,7 +401,7 @@ func (s *gamelifeClient) RequestActivity(ctx context.Context, in *model.QQNetbar
if err != nil {
return nil, ecode.Fail.Sub("获取游戏编码失败")
}
cache, err := s.ensureUserCacheWithParams(ctx, in.PopenId, value.String(), in.NickName, in.BindType)
cache, err := s.ensureUserCacheWithParams(ctx, in.PopenId, value.String(), in.NickName, in.BindType, true)
if err != nil {
return nil, err
}
@ -421,7 +422,7 @@ func (s *gamelifeClient) RequestActivity(ctx context.Context, in *model.QQNetbar
// ensureUserCacheWithParams ensures user cache exists and contains a valid Params string.
// It handles cache retrieval, fallback refresh, Params generation, and cache update.
func (s *gamelifeClient) ensureUserCacheWithParams(ctx context.Context, popenId, appname, nickname string, bindType int) (*model.UserGamelifeCache, error) {
func (s *gamelifeClient) ensureUserCacheWithParams(ctx context.Context, popenId, appname, nickname string, bindType int, isBound bool) (*model.UserGamelifeCache, error) {
cacheKey := fmt.Sprintf(consts.GameLifeUserKey, popenId)
cacheData, err := g.Redis().Get(ctx, cacheKey)
if err != nil {
@ -441,7 +442,7 @@ func (s *gamelifeClient) ensureUserCacheWithParams(ctx context.Context, popenId,
}
if cache.Params == "" {
cache.Params, err = s.buildQueryParams(ctx, popenId, cache, appname, nickname, bindType, true)
cache.Params, err = s.buildQueryParams(ctx, popenId, cache, appname, nickname, bindType, isBound)
if err != nil {
return nil, err
}