feat: 对齐闲鱼续期流程并完善业务管理
对齐官方 WebSocket 批量握手、注册、心跳、ACK、同步恢复及运行时设备标识生命周期。 保留 Cookie 完整属性,接入静默续期和保存登录信息设置,并在凭证更新后重建账号连接。 完善订单与商品同步、卡券和通知渠道交互,更新前端品牌、时间展示及嵌入资源。 补充 Go 与前端回归测试,确保完整检查和生产构建通过。
This commit is contained in:
1 parent
3cc1d4094d
commit
d77c317452
69 files changed
+3169
-819
No files matched your search
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -175,13 +176,31 @@ func (m *Manager) CookiesRefreshSnapshot(ctx context.Context, cookieID, cookieSt
|
||||
}
|
||||
defer func() { _ = page.Close() }()
|
||||
|
||||
if _, err := page.Goto(goofishHomeURL, playwright.PageGotoOptions{
|
||||
WaitUntil: playwright.WaitUntilStateDomcontentloaded,
|
||||
Timeout: playwright.Float(60000),
|
||||
}); err != nil {
|
||||
m.logger.Warn("COOKIES续期访问首页异常", "cookieID", cookieID, "err", err)
|
||||
navigate := func() error {
|
||||
_, err := page.Goto(goofishIMURL, playwright.PageGotoOptions{
|
||||
WaitUntil: playwright.WaitUntilStateDomcontentloaded,
|
||||
Timeout: playwright.Float(60000),
|
||||
})
|
||||
return err
|
||||
}
|
||||
if expectsOfficialSilentLogin(cookieStr) {
|
||||
response, err := page.ExpectResponse("**/newlogin/silentHasLogin.do**", navigate, playwright.PageExpectResponseOptions{Timeout: playwright.Float(7000)})
|
||||
if err != nil {
|
||||
return "", nil, fmt.Errorf("等待官网静默续期请求完成: %w", err)
|
||||
}
|
||||
if response == nil || response.Status() < 200 || response.Status() >= 300 {
|
||||
return "", nil, fmt.Errorf("官网静默续期 HTTP 状态异常")
|
||||
}
|
||||
// 插件在业务成功后立即 location.reload;等待短暂调度窗口,再等待
|
||||
// 新文档进入 DOMContentLoaded,避免提取续期前 Cookie。
|
||||
page.WaitForTimeout(500)
|
||||
_ = page.WaitForLoadState(playwright.PageWaitForLoadStateOptions{
|
||||
State: playwright.LoadStateDomcontentloaded,
|
||||
Timeout: playwright.Float(5000),
|
||||
})
|
||||
} else if err := navigate(); err != nil {
|
||||
m.logger.Warn("COOKIES续期访问消息页异常", "cookieID", cookieID, "err", err)
|
||||
}
|
||||
time.Sleep(quickRenewPageLoadWait)
|
||||
if err := verifyHomeLoginState(page); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
@@ -199,6 +218,27 @@ func (m *Manager) CookiesRefreshSnapshot(ctx context.Context, cookieID, cookieSt
|
||||
return newCookies, newSnapshot, nil
|
||||
}
|
||||
|
||||
func expectsOfficialSilentLogin(cookieStr string) bool {
|
||||
cookies := cookierefresh.ParseCookieString(cookieStr)
|
||||
now := time.Now().UnixMilli()
|
||||
if futureCookieMillis(cookies["sdkSilent"], now) {
|
||||
return false
|
||||
}
|
||||
return futureCookieMillis(cookies["havana_lgc_exp"], now) || futureCookieMillis(cookies["cookie3_bak_exp"], now)
|
||||
}
|
||||
|
||||
func futureCookieMillis(raw string, now int64) bool {
|
||||
raw = strings.TrimSpace(raw)
|
||||
if raw == "" {
|
||||
return false
|
||||
}
|
||||
value, err := strconv.ParseInt(raw, 10, 64)
|
||||
if err != nil {
|
||||
return true
|
||||
}
|
||||
return value > now
|
||||
}
|
||||
|
||||
// CookieRenewSnapshot 兼容旧调用,等价于定时 COOKIES 快照续期。
|
||||
func (m *Manager) CookieRenewSnapshot(ctx context.Context, cookieID, cookieStr string, snapshot []cookierefresh.BrowserCookie, headless bool) (string, []cookierefresh.BrowserCookie, error) {
|
||||
return m.CookiesRefreshSnapshot(ctx, cookieID, cookieStr, snapshot, headless)
|
||||
|
||||
Reference in new issue
Block a user