默认传输通道改为 WSS,http 作为可回退通道
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
# huya-go
|
# huya-go
|
||||||
|
|
||||||
虎牙活动积分兑换/抢购的 Go 复刻版。支持两种传输层,CLI 与 GUI 默认都走 `http`:
|
虎牙活动积分兑换/抢购的 Go 复刻版。支持两种传输层,CLI 与 GUI 默认都走 `wss`:
|
||||||
|
|
||||||
- `http`(默认):走 `https://cdnws.api.huya.com/`,兼容原有命令。
|
- `wss`(默认):浏览器实际使用的通道。先调用 `launch.queryHttpDns` 解析可用 host,再走 TAF `WebSocketCommand` 外层与 WSS 初始化流程(`launch.wsLaunch` → `mobileui.getConfig`)。host 留空即自动解析,解析失败会回退内置默认 host。
|
||||||
- `wss`:实验实现。CLI 需要显式指定 `-transport wss`,GUI 在设置里切换;已按浏览器 HAR 改为 TAF `WebSocketCommand` 外层和 WSS 初始化流程,仍建议先用真实 Cookie 小流量验证。
|
- `http`:走 `https://cdnws.api.huya.com/`,作为可回退通道;CLI 用 `-transport http`,GUI 在设置里切换。
|
||||||
|
|
||||||
## 构建
|
## 构建
|
||||||
|
|
||||||
@@ -57,21 +57,23 @@ CLI 示例:
|
|||||||
直接兑换指定 PID:
|
直接兑换指定 PID:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
./huya-go -cmd exchange -sid 2203 -pid 12889 -cookie-file cookie.txt -transport http
|
./huya-go -cmd exchange -sid 2203 -pid 12889 -cookie-file cookie.txt
|
||||||
```
|
```
|
||||||
|
|
||||||
按奖品名轮询并抢购:
|
按奖品名轮询并抢购:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
./huya-go -cmd monitor -sid 2203 -name 小黄鸭 -cookie-file cookie.txt -transport http -loops 20 -delay 120 -concurrency 5
|
./huya-go -cmd monitor -sid 2203 -name 小黄鸭 -cookie-file cookie.txt -loops 20 -delay 120 -concurrency 5
|
||||||
```
|
```
|
||||||
|
|
||||||
定时开始:
|
定时开始:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
./huya-go -cmd monitor -sid 2203 -pid 12889 -cookie-file cookie.txt -transport http -at "2026-07-06 20:00:00"
|
./huya-go -cmd monitor -sid 2203 -pid 12889 -cookie-file cookie.txt -at "2026-07-06 20:00:00"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
以上默认都走 `wss`。需要回退到 http 传输时,给任意命令加上 `-transport http`。
|
||||||
|
|
||||||
## 多开(多实例)
|
## 多开(多实例)
|
||||||
|
|
||||||
同一台机器可以同时启动多个实例,互不干扰:
|
同一台机器可以同时启动多个实例,互不干扰:
|
||||||
@@ -103,7 +105,7 @@ GUI 与 CLI 共用同一套结构化日志(分类 + 等级 + 账号标签)
|
|||||||
- `-min-left`:目标奖品最少剩余库存,`0` 表示不限制(CLI 与 GUI 设置都支持)。
|
- `-min-left`:目标奖品最少剩余库存,`0` 表示不限制(CLI 与 GUI 设置都支持)。
|
||||||
- `-cookie`:单账号 Cookie。
|
- `-cookie`:单账号 Cookie。
|
||||||
- `-cookie-file`:多账号 Cookie 文件。
|
- `-cookie-file`:多账号 Cookie 文件。
|
||||||
- `-transport`:`http` 或 `wss`,默认 `http`;WSS 仍为实验通道。
|
- `-transport`:`wss` 或 `http`,默认 `wss`。
|
||||||
- `-wss-host`:WebSocket host。默认留空,自动调用 `launch.queryHttpDns` 解析(带 TTL 缓存、多 host 轮询),解析失败时回退内置默认 host;需要固定时可显式指定。
|
- `-wss-host`:WebSocket host。默认留空,自动调用 `launch.queryHttpDns` 解析(带 TTL 缓存、多 host 轮询),解析失败时回退内置默认 host;需要固定时可显式指定。
|
||||||
- `-timeout`:单次调用超时秒数。
|
- `-timeout`:单次调用超时秒数。
|
||||||
- `-loops`、`-delay`、`-concurrency`:轮询次数、轮询间隔、并发账号数。
|
- `-loops`、`-delay`、`-concurrency`:轮询次数、轮询间隔、并发账号数。
|
||||||
|
|||||||
+1
-1
@@ -49,7 +49,7 @@ func main() {
|
|||||||
at = flag.String("at", "", "定时开始时间,支持 RFC3339 或 2006-01-02 15:04:05")
|
at = flag.String("at", "", "定时开始时间,支持 RFC3339 或 2006-01-02 15:04:05")
|
||||||
leadMS = flag.Int("lead", 2500, "monitor 相对 -at 提前启动毫秒")
|
leadMS = flag.Int("lead", 2500, "monitor 相对 -at 提前启动毫秒")
|
||||||
timeoutSec = flag.Int("timeout", 15, "单次请求超时秒数")
|
timeoutSec = flag.Int("timeout", 15, "单次请求超时秒数")
|
||||||
transport = flag.String("transport", "http", "传输层:http/wss")
|
transport = flag.String("transport", "wss", "传输层:wss/http,默认 wss")
|
||||||
wssHost = flag.String("wss-host", "", "WSS host,留空则通过 launch.queryHttpDns 自动解析")
|
wssHost = flag.String("wss-host", "", "WSS host,留空则通过 launch.queryHttpDns 自动解析")
|
||||||
prewarm = flag.Bool("prewarm", true, "monitor 开始前预热账号连接")
|
prewarm = flag.Bool("prewarm", true, "monitor 开始前预热账号连接")
|
||||||
directExchange = flag.Bool("direct-exchange", true, "monitor 已知 PID 时跳过列表直接兑换")
|
directExchange = flag.Bool("direct-exchange", true, "monitor 已知 PID 时跳过列表直接兑换")
|
||||||
|
|||||||
@@ -492,7 +492,7 @@ function newCookieID(): string {
|
|||||||
|
|
||||||
function pickConfig(values: Partial<UiConfig>): UiConfig {
|
function pickConfig(values: Partial<UiConfig>): UiConfig {
|
||||||
return {
|
return {
|
||||||
transport: values.transport || 'http',
|
transport: values.transport || 'wss',
|
||||||
wssHost: values.wssHost || '',
|
wssHost: values.wssHost || '',
|
||||||
sid: Number(values.sid || 0),
|
sid: Number(values.sid || 0),
|
||||||
pid: Number(values.pid || 0),
|
pid: Number(values.pid || 0),
|
||||||
@@ -1514,7 +1514,7 @@ export default function Dashboard() {
|
|||||||
>
|
>
|
||||||
<Tag color="blue">{instanceInfo?.name || '默认实例'}</Tag>
|
<Tag color="blue">{instanceInfo?.name || '默认实例'}</Tag>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
<Tag>{String(watchedTransport || 'http').toUpperCase()}</Tag>
|
<Tag>{String(watchedTransport || 'wss').toUpperCase()}</Tag>
|
||||||
<Button icon={<Settings size={16} />} onClick={() => setSettingsOpen(true)}>
|
<Button icon={<Settings size={16} />} onClick={() => setSettingsOpen(true)}>
|
||||||
设置
|
设置
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
+2
-2
@@ -283,7 +283,7 @@ func (a *App) Shutdown(ctx context.Context) {
|
|||||||
|
|
||||||
func (a *App) DefaultConfig() Config {
|
func (a *App) DefaultConfig() Config {
|
||||||
return Config{
|
return Config{
|
||||||
Transport: "http",
|
Transport: "wss",
|
||||||
WSSHost: "",
|
WSSHost: "",
|
||||||
SID: 2203,
|
SID: 2203,
|
||||||
Loops: 20,
|
Loops: 20,
|
||||||
@@ -606,7 +606,7 @@ func (a *App) emit(event string, data any) {
|
|||||||
|
|
||||||
func normalizeConfig(cfg Config) Config {
|
func normalizeConfig(cfg Config) Config {
|
||||||
if strings.TrimSpace(cfg.Transport) == "" {
|
if strings.TrimSpace(cfg.Transport) == "" {
|
||||||
cfg.Transport = "http"
|
cfg.Transport = "wss"
|
||||||
}
|
}
|
||||||
// WSSHost 留空表示走 launch.queryHttpDns 自动解析,不在这里补默认值。
|
// WSSHost 留空表示走 launch.queryHttpDns 自动解析,不在这里补默认值。
|
||||||
if cfg.Loops <= 0 {
|
if cfg.Loops <= 0 {
|
||||||
|
|||||||
@@ -16,15 +16,10 @@ type ActivityClient interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewActivityClient 按传输层创建活动客户端,供 CLI 和 GUI 共用。
|
// NewActivityClient 按传输层创建活动客户端,供 CLI 和 GUI 共用。
|
||||||
|
// 默认走 wss(留空即 wss);需要回退时显式传 "http"。
|
||||||
func NewActivityClient(transport, wssHost string, timeout time.Duration, logger func(string)) (ActivityClient, func(), error) {
|
func NewActivityClient(transport, wssHost string, timeout time.Duration, logger func(string)) (ActivityClient, func(), error) {
|
||||||
switch strings.ToLower(strings.TrimSpace(transport)) {
|
switch strings.ToLower(strings.TrimSpace(transport)) {
|
||||||
case "", "http":
|
case "", "wss", "ws", "websocket":
|
||||||
client := NewHTTPClient(logger)
|
|
||||||
if timeout > 0 {
|
|
||||||
client.Client.Timeout = timeout
|
|
||||||
}
|
|
||||||
return client, func() {}, nil
|
|
||||||
case "wss", "ws", "websocket":
|
|
||||||
client := NewWSSClient(logger)
|
client := NewWSSClient(logger)
|
||||||
// 留空(或沿用历史默认 host)表示交给 launch.queryHttpDns 自动解析,
|
// 留空(或沿用历史默认 host)表示交给 launch.queryHttpDns 自动解析,
|
||||||
// 只有显式指定的其它 host 才固定使用。
|
// 只有显式指定的其它 host 才固定使用。
|
||||||
@@ -36,6 +31,12 @@ func NewActivityClient(transport, wssHost string, timeout time.Duration, logger
|
|||||||
client.CallTimeout = timeout
|
client.CallTimeout = timeout
|
||||||
}
|
}
|
||||||
return client, func() { _ = client.Close() }, nil
|
return client, func() { _ = client.Close() }, nil
|
||||||
|
case "http":
|
||||||
|
client := NewHTTPClient(logger)
|
||||||
|
if timeout > 0 {
|
||||||
|
client.Client.Timeout = timeout
|
||||||
|
}
|
||||||
|
return client, func() {}, nil
|
||||||
default:
|
default:
|
||||||
return nil, func() {}, fmt.Errorf("未知传输层: %s", transport)
|
return nil, func() {}, fmt.Errorf("未知传输层: %s", transport)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user