fix: 公众号保活续期与可观测 (v2.2.1)

- 保活追加带 token 的 /cgi-bin/home 续期请求(we-mp-rss/hive-mp 同源做法)
- 服务端未续期时本地延长临期会话 Cookie 到 7 天(仅在线验证通过后)
- 新增保活运行记录 + 在线页显示会话有效期/上次保活时间/运行记录
- 桥接新增 mpState / mpKeepAlive 方法
- 修复保活锁与 syncing 状态崩溃残留导致保活永久卡死
This commit is contained in:
3970260761 committed 2026-11-10 22:37:50 +08:00
1 parent 35284395b3
commit 8c2ce3dcb9
6 files changed
+267 -13

No files matched your search

+19
View File
@@ -129,6 +129,25 @@ export function parseMpAuth(html: string): MpAuthInfo | null {
}
}
/** 公众号会话关键 Cookie(按重要性排序,与社区保活工具 hive-mp 同源的取法) */
export const MP_SESSION_COOKIE_NAMES = ['slave_sid', 'slave_user', 'bizuin', 'uin', 'pass_ticket'] as const
/**
* 取公众号会话的过期时间(秒级时间戳,与 chrome.cookies.expirationDate 同单位)。
* 会话是否即将到期只看这些关键 Cookie,统计类 Cookie 不参与。
*/
export function mpSessionExpiry(
cookies: Array<{ name: string; expirationDate?: number }>,
): number | null {
for (const name of MP_SESSION_COOKIE_NAMES) {
const c = cookies.find((x) => x.name === name)
if (c && typeof c.expirationDate === 'number' && c.expirationDate > 0) {
return c.expirationDate
}
}
return null
}
/**
* 按 Cookie 规范拼装 Cookie 请求头
* 只包含对目标 URL 生效(domain/path 匹配)的 Cookie