Files
huya-go/internal/huya/client.go
T
yml2213 7dadcd1644 feat(role): 增加用户绑定角色信息查询与作战表展示
- 逆向并实现虎牙活动绑角色接口 webActUI.checkUserBindGameAccount,支持精准解析游戏角色名、区服和平台
- 增加本地持久化 roles.json 存储,启动即回显角色信息无需重复请求
- 前端账号作战表与 CK 管理列表整合角色展示([微信-安卓] 角色名),直观区分账号归属
- 工具栏增加「查询角色」按钮,并以兑换记录中的历史账号作为双重兜底
- 升级版本至 v0.5.5 并成功交叉编译 Windows 产物
2026-10-19 12:09:24 +08:00

45 lines
1.7 KiB
Go

package huya
import (
"context"
"fmt"
"strings"
"time"
)
// ActivityClient 抽象虎牙活动接口,HTTP 与 WSS 传输都实现它。
type ActivityClient interface {
GetActPrizeList(ctx context.Context, uid int64, cookie string, sid int32) (*GetActPrizeListResp, error)
QueryUserScore(ctx context.Context, uid int64, cookie string, sid int32) (*GetUserScoreResp, error)
GetUserPrizeRecords(ctx context.Context, uid int64, cookie string, sid int32) (*GetUserPrizeRecordsResp, error)
ScoreExchangePrize(ctx context.Context, uid int64, cookie string, sid, pid int32) (*ScoreExchangePrizeResp, error)
CheckUserBindGameAccount(ctx context.Context, uid int64, cookie string, bActID int32) (*CheckUserBindGameAccountResp, error)
}
// NewActivityClient 按传输层创建活动客户端,供 CLI 和 GUI 共用。
// 默认走 wss(留空即 wss);需要回退时显式传 "http"。
func NewActivityClient(transport, wssHost string, timeout time.Duration, logger func(string)) (ActivityClient, func(), error) {
switch strings.ToLower(strings.TrimSpace(transport)) {
case "", "wss", "ws", "websocket":
client := NewWSSClient(logger)
// 留空(或沿用历史默认 host)表示交给 launch.queryHttpDns 自动解析,
// 只有显式指定的其它 host 才固定使用。
host := strings.TrimSpace(wssHost)
if host != "" && host != DefaultWSSHost {
client.Host = host
}
if timeout > 0 {
client.CallTimeout = timeout
}
return client, func() { _ = client.Close() }, nil
case "http":
client := NewHTTPClient(logger)
if timeout > 0 {
client.Client.Timeout = timeout
}
return client, func() {}, nil
default:
return nil, func() {}, fmt.Errorf("未知传输层: %s", transport)
}
}