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) } // 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) } }