Files
huya-go/internal/huya/client.go
T
yml2213 36aadae90a 按 10.13 抓包对齐 WSS:host 自动解析、exp 回传、pingSignal 与兑换记录字段
- 新增 launch.queryHttpDns:类型定义 + HTTPClient.QueryHttpDns + WSSClient.resolveHost(TTL 缓存、多 host 轮询、失败回退默认 host);Host 留空或等于历史默认值即视为自动解析
- WSS 握手 baseinfo 补 tag5=exp 与 tag10 空 customHeaders;UpdateUserExpsReq(cmd23) 改为回传 getConfig 的版本 map(缓存供重连复用)
- 新增 launch.pingSignal:HTTP 预热改走 pingSignal,WSS 预热在建连后探测业务通道(失败仅记日志)
- UserPrizeInfo 补 tag12 orderId/tag14 图标/tag16 prizeId/tag17 shopItemId/tag19 itemId/tag20 ext/tag21 exchangeDate,前端复盘表加订单号列
- taf 补 WriteListString/ReadListString/ReadMapStringInt64/ReadMapStringStruct
- 新增 internal/huya/launch_test.go:用抓包真实报文做字节级夹具(baseinfo 122B、queryHttpDns 请求 93B、记录 308B 等)
- CLI -wss-host 默认改为留空;GUI 设置支持留空并给出占位提示;README/WSS_NOTES 同步协议细节
2026-10-13 20:19:14 +08:00

43 lines
1.5 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)
}
// NewActivityClient 按传输层创建活动客户端,供 CLI 和 GUI 共用。
func NewActivityClient(transport, wssHost string, timeout time.Duration, logger func(string)) (ActivityClient, func(), error) {
switch strings.ToLower(strings.TrimSpace(transport)) {
case "", "http":
client := NewHTTPClient(logger)
if timeout > 0 {
client.Client.Timeout = timeout
}
return client, func() {}, nil
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
default:
return nil, func() {}, fmt.Errorf("未知传输层: %s", transport)
}
}