fix: read qdreader user id from qdheader payload

This commit is contained in:
2026-05-17 17:17:44 +08:00
parent e746135eca
commit 336beb79d6
3 changed files with 19 additions and 2 deletions
+2 -1
View File
@@ -34,8 +34,9 @@ hostname = h5.if.qidian.com
5. 失败弹窗可以保留简短错误,例如“请求中没有 Cookie”“无法识别 uid”。
6. uid 识别优先级:
- `QDHeader` 第一段是有效数字 uid 时优先使用;
- Stream 抓包确认:当 `QDHeader` 第一段是 `(null)` 时,第 12 段(索引 11)可能是真实 `UserId`,应优先于 `ywguid` 使用;
- 响应体里递归查找 `UserId` / `userId` / `uid`
- `QDHeader` 第一段是 `(null)`回退到 Cookie 里的 `ywguid` / `gwguid` / `guid`,仅用于确认账号已识别,不在通知标题显示 uid。
- 最后再回退到 Cookie 里的 `ywguid` / `gwguid` / `guid`,仅用于确认账号已识别,不在通知标题显示 uid。
- 只读请求头 Cookie`script-request-header` 即可;
- 需要读取响应 body 辅助解析 uid:用 `script-response-body`
QDReader 当前需要兼容从响应 body 取 `UserId`,所以使用 `script-response-body`
+7 -1
View File
@@ -39,7 +39,13 @@ function uidFromQDHeader(qdheader) {
const decoded = b64decode(qdheader)
if (!decoded) return ''
const parts = decoded.split('|').map(x => String(x || '').trim())
return isRealUid(parts[0])
// QDReader 抓包里 QDHeader 第一段可能是 (null),真实 UserId 常在第 12 段(索引 11)。
// 只接受足够长的数字,避免把 1179/2556/版本号等设备字段误当账号。
for (const idx of [0, 11]) {
const uid = isRealUid(parts[idx])
if (uid) return uid
}
return ''
}
function parseJson(s, def) { try { return JSON.parse(s) } catch (e) { return def } }
function findUid(obj) {
+10
View File
@@ -51,6 +51,16 @@ function run({ cookie = '', body = '', headerName = 'Cookie' }) {
assert.equal(notices[0][1], '抓取成功');
}
{
const streamQdheader = 'KG51bGwpfChudWxsKXwxMTc5fDI1NTZ8KG51bGwpfDE2LjEwfDB8aU9TL2lQaG9uZS8obnVsbCl8MHwobnVsbCl8KG51bGwpfDQ3NTcwMDk3NXwxNzc5MDA5MTM2MDAwfDB8KG51bGwpfHx8KG51bGwpfChudWxsKXww';
const { notices } = run({
cookie: `QDHeader=${streamQdheader}; ywguid=120098575768; QDH=abc`,
body: JSON.stringify({ Data: { Guid: '120098575768', UserId: '475700975' }, Result: '0' }),
});
assert.equal(notices[0][1], '抓取成功');
assert.match(notices[0][2], /^启点ck /);
}
{
const { notices, donePayloads } = run({
cookie: 'cmfuToken=abc; QDH=def',