封装游戏人生背包接口

This commit is contained in:
2025-06-23 17:12:53 +08:00
parent 0019e65ebf
commit 7d167dcf52

View File

@ -39,6 +39,7 @@ type gamelifeClient struct {
unBoundURLMap map[string]string
getBoundURL map[string]string
taskURLMap map[string]string
packageURLMap map[string]string
}
// URLMaps defines the URL mappings for different environments.
@ -48,6 +49,7 @@ var URLMaps = struct {
UnBound map[string]string
GetBound map[string]string
Task map[string]string
Package map[string]string
}{
KeyIV: map[string]string{
"test": "https://api-test.nes.smoba.qq.com/pvpesport.sgamenes.commcgi.commcgi/GetExplatSecret",
@ -69,6 +71,10 @@ var URLMaps = struct {
"test": "https://api-test.cafe.qq.com/netbar.cafe.open_api.open_api/",
"prod": "https://api.cafe.qq.com/netbar.cafe.open_api.open_api/",
},
Package: map[string]string{
"test": "https://test.igame.qq.com/tip/ingame-page/feature/add-game-life/igame-game-life-web/#/index/goods",
"prod": "https://igame.qq.com/tip/ingame-page/feature/add-game-life/igame-game-life-web/#/index/goods",
},
}
var (
@ -99,6 +105,7 @@ func newGamelifeClient(ctx context.Context) *gamelifeClient {
unBoundURLMap: URLMaps.UnBound,
getBoundURL: URLMaps.GetBound,
taskURLMap: URLMaps.Task,
packageURLMap: URLMaps.Package,
}
glog.Info(ctx, "Initialized gamelifeClient successfully", map[string]interface{}{
"plat_id": cfg.PlatID,
@ -188,6 +195,22 @@ func (s *gamelifeClient) GetUrl(ctx context.Context, popenID, appName, nickname
}
return fmt.Sprintf("%s?%s", rootURL, params), nil
}
func (s *gamelifeClient) GetGamelifePackageUrl(ctx context.Context, popenID, appName string, bindType int) (string, error) {
// 从配置中获取 package URL 前缀
packageURL := s.packageURLMap[s.config.Mode]
// 获取用户缓存
cache, err := s.ensureUserCache(ctx, popenID)
if err != nil {
return "", err
}
params, err := s.buildQueryParams(ctx, popenID, cache, appName, "", bindType, true)
if err != nil {
return "", err
}
return fmt.Sprintf("%s?%s", packageURL, params), nil
}
// 通用缓存获取函数,只负责获取/刷新 aes、iv、token
func (s *gamelifeClient) ensureUserCacheGeneral(
@ -465,6 +488,7 @@ func (s *gamelifeClient) RequestActivity(ctx context.Context, in *model.QQNetbar
return nil, ecode.Fail.Sub("请求出现异常")
}
return &result, nil
default:
return nil, ecode.Fail.Sub(fmt.Sprintf("不支持的任务: %s", in.ServiceName))
}