From 02f1e0278bf3583939bf70fc0bf8d3bd8af917bc Mon Sep 17 00:00:00 2001 From: lu8010252 Date: Sun, 15 Nov 2026 20:28:44 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix(dumate):=20=E6=89=AB=E7=A0=81=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E5=90=8E=E8=A1=A5=E9=BD=90=20bce-user-info=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=A2=86=E5=8F=96=E6=8A=A5=20csrftoken=20?= =?UTF-8?q?=E7=BC=BA=E5=A4=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 现象:扫码登录成功后,账号能查到余额,但每日领取失败并提示 「Cookie 缺少 bce-user-info(无法生成 csrftoken)」。 原因:控制台首页(/dumate/channel 等)并不下发 bce-user-info, 会话里只有 BDUSS / bce-sessionid 时 extractDumateCsrfToken 返回空。 修复:新增 healDumateCookies(),缺该 cookie 时请求 /api/dumate/app/token/get,从 Set-Cookie 的 bce-login-accountid 取账户 ID 作为 bce-user-info 的值(实测该值就是账户 ID,服务端按 cookie 原文与 csrftoken 双提交校验)。扫码链路入库前补齐, 领取时也兜底一次,避免存量账号需要重新登录。 实测:补齐后领取接口返回 checked-in「已领取今日登录赠送积分」; 若把值写成 timestamp|accountId 则返回「登录凭证已过期」, 确认必须为纯账户 ID。 --- src/dumateClient.js | 63 +++++++++++++++++++++++++++++++++++++++++++-- src/dumateQr.js | 11 +++++++- 2 files changed, 71 insertions(+), 3 deletions(-) diff --git a/src/dumateClient.js b/src/dumateClient.js index 41d7ebe..a7dc046 100644 --- a/src/dumateClient.js +++ b/src/dumateClient.js @@ -112,6 +112,56 @@ export function extractDumateUserId(cookies) { return token; } +/** + * 补齐 bce-user-info:扫码登录、本机导入拿到的会话常常只有 BDUSS / bce-sessionid, + * 而领取接口需要 csrftoken,其值就是 bce-user-info 的原文(等于 bce 账户 ID)。 + * 控制台首页不一定下发该 cookie,这里调 /api/dumate/app/token/get, + * 从 Set-Cookie 的 bce-login-accountid 取账户 ID 补上。 + * @returns {Promise} 补好后的 cookie 数组;无需补或失败返回 null + */ +export async function healDumateCookies(cookies, fetchImpl) { + const list = Array.isArray(cookies) ? cookies : parseDumateCookies(cookies); + if (list.some((c) => c.name === 'bce-user-info' && c.value)) return null; + const doIt = fetchImpl || ((u, init) => fetchJsonRace(u, { ...init, timeoutMs: FETCH_TIMEOUT_MS })); + try { + const res = await doIt(`${DUMATE_CONSOLE_ORIGIN}/api/dumate/app/token/get`, { + headers: { + Cookie: buildDumateCookieHeader(list), + Accept: 'application/json', + Origin: DUMATE_CONSOLE_ORIGIN, + Referer: `${DUMATE_CONSOLE_ORIGIN}/dumate/channel`, + 'User-Agent': DUMATE_USER_AGENT, + }, + redirect: 'manual', + }); + if (res.status < 200 || res.status >= 300) return null; + const raw = typeof res.headers?.getSetCookie === 'function' ? res.headers.getSetCookie() : []; + const extra = []; + let accountId = ''; + for (const item of raw) { + const [pair] = String(item).split(';'); + const i = pair.indexOf('='); + if (i <= 0) continue; + const name = pair.slice(0, i).trim(); + const value = pair.slice(i + 1).trim(); + if (!name) continue; + if (name === 'bce-login-accountid') { + try { + accountId = decodeURIComponent(value); + } catch { + accountId = value; + } + } + extra.push({ name, value, domain: DUMATE_CONSOLE_HOST }); + } + if (!accountId) return null; + const kept = list.filter((c) => !extra.some((e) => e.name === c.name)); + return [...kept, ...extra, { name: 'bce-user-info', value: accountId, domain: DUMATE_CONSOLE_HOST }]; + } catch { + return null; + } +} + /** * 账号脱敏掩码显示 */ @@ -196,8 +246,17 @@ export async function verifyDumateSession(credentialInput, { fetchImpl } = {}) { */ export async function checkinDumate(account, { fetchImpl } = {}) { const cookie = account?.meta?.cookieSiteSession?.cookie || account?.token || ''; - const cookies = parseDumateCookies(cookie); - const csrftoken = extractDumateCsrfToken(cookies); + let cookies = parseDumateCookies(cookie); + let csrftoken = extractDumateCsrfToken(cookies); + + // 会话里缺 bce-user-info 时先补齐(扫码登录、本机导入常见) + if (!csrftoken) { + const healed = await healDumateCookies(cookies, fetchImpl).catch(() => null); + if (healed) { + cookies = healed; + csrftoken = extractDumateCsrfToken(cookies); + } + } if (!csrftoken) { return { status: 'failed', error: t('Cookie 缺少 bce-user-info(无法生成 csrftoken)') }; diff --git a/src/dumateQr.js b/src/dumateQr.js index ef5154e..1de2d39 100644 --- a/src/dumateQr.js +++ b/src/dumateQr.js @@ -31,6 +31,7 @@ import { randomBytes } from 'node:crypto'; import { FETCH_TIMEOUT_MS } from './constants.js'; +import { healDumateCookies } from './dumateClient.js'; export const DUMATE_QR_CONSOLE_URL = 'https://console.bce.baidu.com/dumate/channel'; export const DUMATE_QR_UA = @@ -161,7 +162,15 @@ export async function qrQuickLogin(pp) { if (!loc) { const onConsole = /^https:\/\/console\.bce\.baidu\.com\//.test(url); const hasSess = jar.has('bce-sessionid'); - if (onConsole && r.status === 200 && hasSess) return { cookies: jar.all(), account: pf.username }; + if (onConsole && r.status === 200 && hasSess) { + // 控制台首页不一定下发 bce-user-info,缺了就用 dumate 应用 token 接口补齐账户 ID + let cookies = jar.all(); + if (!jar.has('bce-user-info')) { + const healed = await healDumateCookies(cookies).catch(() => null); + if (healed) cookies = healed; + } + return { cookies, account: pf.username }; + } break; } url = new URL(loc, url).href; From 88dd1d4972e382a8931e66951e3090d90b9f10dd Mon Sep 17 00:00:00 2001 From: lu8010252 Date: Sun, 15 Nov 2026 20:31:49 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix(checkin):=20=E6=8E=A5=E5=8F=A3=E6=9C=AA?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E7=A7=AF=E5=88=86=E6=95=B0=E9=87=8F=E6=97=B6?= =?UTF-8?q?=E4=B8=8D=E5=86=8D=E6=89=93=E5=8D=B0=20+undefined?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/checkin.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/checkin.js b/src/checkin.js index daf75fa..8a2ce18 100644 --- a/src/checkin.js +++ b/src/checkin.js @@ -295,7 +295,12 @@ async function runTickInner(opts) { if (outcome.status === 'checked-in') { memo[account.id] = todayFor; account.lastCheckin = new Date().toISOString(); - logger.info('CHECKIN', '{label} 领取成功 +{amount} {unit}', { label, amount: outcome.claimedAmount, unit: CHECKIN_UNIT[account.provider] || 'Credits' }); + const amount = Number.isFinite(outcome.claimedAmount) ? outcome.claimedAmount : null; + if (amount === null) { + logger.info('CHECKIN', '{label} 领取成功(接口未返回积分数量)', { label }); + } else { + logger.info('CHECKIN', '{label} 领取成功 +{amount} {unit}', { label, amount, unit: CHECKIN_UNIT[account.provider] || 'Credits' }); + } } else if (outcome.status === 'already') { memo[account.id] = todayFor; account.lastCheckin = account.lastCheckin || new Date().toISOString();