feat(seckill): 增加只读预演并强化代理风控切换

This commit is contained in:
yml
2026-11-22 14:52:46 +08:00
parent 70612a8f0c
commit e20907800d
20 changed files with 1916 additions and 40 deletions
+28
View File
@@ -181,6 +181,9 @@ func (s *Scheduler) runPeaceLockPay(attempt types.ExchangeAttempt, ctl *runContr
if csrf == "" {
token, err := cli.GenerateCSRF(attempt.Account.Cookie)
if err != nil {
if isProxyRiskBusinessError(err) {
s.handleProxyBusinessRisk(attempt.Account.Name, cli, err)
}
out.result.Message = "失败|生成鉴权token失败: " + err.Error()
return out
}
@@ -214,6 +217,9 @@ func (s *Scheduler) runPeaceLockPay(attempt types.ExchangeAttempt, ctl *runContr
if err != nil {
out.result.Message = "失败|" + err.Error()
kind := lockErrorKind(err)
if isProxyRiskBusinessError(err) {
s.handleProxyBusinessRisk(attempt.Account.Name, cli, err)
}
out.stockOut = kind == orderErrStockOut
out.throttled = kind == orderErrThrottled
out.terminal = kind == orderErrTerminal
@@ -318,6 +324,12 @@ func (s *Scheduler) payLockedOrder(cli *client.DouyuClient, attempt types.Exchan
if err == nil {
return info, nil
}
if isProxyRiskBusinessError(err) {
s.handleProxyBusinessRisk(attempt.Account.Name, cli, err)
if next := s.clientForAccount(attempt.Account.Name); next != nil {
cli = next
}
}
kind := payErrorKind(err)
if kind == orderErrTerminal {
@@ -394,6 +406,9 @@ func (s *Scheduler) runDirectExchange(attempt types.ExchangeAttempt, reuseCache
if csrf == "" {
token, err := cli.GenerateCSRF(attempt.Account.Cookie)
if err != nil {
if isProxyRiskBusinessError(err) {
s.handleProxyBusinessRisk(attempt.Account.Name, cli, err)
}
out.result.Message = "失败|生成鉴权token失败: " + err.Error()
return out
}
@@ -422,6 +437,9 @@ func (s *Scheduler) runDirectExchange(attempt types.ExchangeAttempt, reuseCache
out.result.Message = "失败|" + errMsg
out.terminal = isTerminalAccountMessage(errMsg)
kind := lockErrorKind(err)
if isProxyRiskBusinessError(err) {
s.handleProxyBusinessRisk(attempt.Account.Name, cli, err)
}
out.stockOut = kind == orderErrStockOut
out.throttled = kind == orderErrThrottled
if isLimitReachedMessage(errMsg) {
@@ -525,6 +543,9 @@ func (s *Scheduler) runXiaodianAttempt(attempt types.ExchangeAttempt) types.Exch
attempt.Account.Name, attempt.Product.CommodityName, attempt.Index)
exchangeInfo, err := cli.ExchangeProduct(attempt.Account.Cookie, attempt.Product, nil)
if err != nil {
if isProxyRiskBusinessError(err) {
s.handleProxyBusinessRisk(attempt.Account.Name, cli, err)
}
result.Message = "失败|" + err.Error()
return result
}
@@ -613,6 +634,13 @@ func lockErrorKind(err error) orderErrorKind {
return orderErrTransient
}
func isProxyRiskBusinessError(err error) bool {
code, msg := orderErrorInfo(err)
return code == apiActivityHot ||
strings.Contains(msg, "1644400007") ||
strings.Contains(msg, "活动火爆")
}
// stockOutHint 判断服务端是否明确表示该商品已售罄。
// 只有这一类才允许判定"商品当前不可抢"。
func stockOutHint(message string) bool {