Files
go-taobao/config/config.go
2026-02-09 16:05:56 +08:00

85 lines
1.9 KiB
Go

package config
import "time"
// RushConfig 抢购配置
type RushConfig struct {
// 抢购目标时间
TargetTime time.Time
// 提交失败最大重试次数
MaxRetry int
// 重试间隔
RetryInterval time.Duration
// 提前多久预加载购物车页面
PreloadBefore time.Duration
// 提前多少毫秒开始提交(网络延迟补偿)
SubmitAdvance time.Duration
// Cookie 文件路径
CookieFile string
// 浏览器用户数据目录 ID
AccountID int
}
// DefaultConfig 返回默认抢购配置
func DefaultConfig() *RushConfig {
// 默认目标: 2026-02-10 20:00:00 CST
loc, _ := time.LoadLocation("Asia/Shanghai")
target := time.Date(2026, 2, 10, 20, 0, 0, 0, loc)
return &RushConfig{
TargetTime: target,
MaxRetry: 5,
RetryInterval: 200 * time.Millisecond,
PreloadBefore: 30 * time.Second,
SubmitAdvance: 500 * time.Millisecond,
CookieFile: "account_cookie.json",
AccountID: 1,
}
}
// 淘宝关键页面 URL
const (
LoginURL = "https://login.taobao.com/havanaone/login/login.htm"
CartURL = "https://cart.taobao.com/cart.htm"
)
// TimeAPIs 时间同步 API 列表(按优先级排列,依次降级)
var TimeAPIs = []TimeAPIConfig{
{
Name: "淘宝 H5",
URL: "https://h5api.m.taobao.com/h5/mtop.common.getTimestamp/",
Type: TimeAPITypeTaobaoH5,
},
{
Name: "苏宁",
URL: "https://quan.suning.com/getSysTime.do",
Type: TimeAPITypeSuning,
},
{
Name: "淘宝主站",
URL: "https://www.taobao.com",
Type: TimeAPITypeHTTPHeader,
},
{
Name: "天猫",
URL: "https://www.tmall.com",
Type: TimeAPITypeHTTPHeader,
},
}
// TimeAPIType 时间 API 类型
type TimeAPIType int
const (
TimeAPITypeTaobaoH5 TimeAPIType = iota // 淘宝 H5 JSON 响应
TimeAPITypeSuning // 苏宁 JSON 响应
TimeAPITypeHTTPHeader // 使用 HTTP Date 响应头
)
// TimeAPIConfig 时间 API 配置
type TimeAPIConfig struct {
Name string
URL string
Type TimeAPIType
}