fix: fallback qdreader uid to ywguid

This commit is contained in:
2026-05-17 16:34:50 +08:00
parent cf1ad9e68d
commit 3ad87d2783
3 changed files with 26 additions and 8 deletions
+4 -1
View File
@@ -32,7 +32,10 @@ hostname = h5.if.qidian.com
4. 不要在弹窗正文加说明、账号数、变量名、截断摘要;BOSS 要直接复制整段命令。
5. 失败弹窗可以保留简短错误,例如“请求中没有 Cookie”“无法识别 uid”。
6. Rewrite 类型按实际取值选择
6. uid 识别优先级
- `QDHeader` 第一段是有效数字 uid 时优先使用;
- 响应体里递归查找 `UserId` / `userId` / `uid`
-`QDHeader` 第一段是 `(null)`,回退到 Cookie 里的 `ywguid` / `gwguid` / `guid`,避免通知标题显示 `uid:null`
- 只读请求头 Cookie`script-request-header` 即可;
- 需要读取响应 body 辅助解析 uid:用 `script-response-body`
QDReader 当前需要兼容从响应 body 取 `UserId`,所以使用 `script-response-body`
+14 -5
View File
@@ -31,17 +31,23 @@ function b64decode(s) {
while (raw.length % 4) raw += '='
try { return decodeURIComponent(escape(atob(raw))) } catch (e) { return '' }
}
function isRealUid(uid) {
uid = String(uid === undefined || uid === null ? '' : uid).trim()
return /^\d{5,}$/.test(uid) ? uid : ''
}
function uidFromQDHeader(qdheader) {
const decoded = b64decode(qdheader)
return decoded ? String(decoded.split('|')[0] || '').trim() : ''
if (!decoded) return ''
const parts = decoded.split('|').map(x => String(x || '').trim())
return isRealUid(parts[0])
}
function parseJson(s, def) { try { return JSON.parse(s) } catch (e) { return def } }
function findUid(obj) {
if (!obj || typeof obj !== 'object') return ''
const keys = ['UserId', 'userId', 'UserID', 'userid', 'uid', 'UID']
for (const key of keys) {
const val = obj[key]
if (val !== undefined && val !== null && String(val).trim()) return String(val).trim()
const uid = isRealUid(obj[key])
if (uid) return uid
}
for (const key in obj) {
const val = obj[key]
@@ -56,9 +62,12 @@ function getUid(cookie, body) {
const jar = parseCookie(cookie)
let uid = uidFromQDHeader(jar.QDHeader || jar.qdheader || jar.QDHEADER || '')
if (uid) return uid
if (jar.uid) return String(jar.uid)
uid = isRealUid(jar.uid || jar.userid || jar.userId || jar.UserId)
if (uid) return uid
const obj = parseJson(body || '', null)
return findUid(obj)
uid = findUid(obj)
if (uid) return uid
return isRealUid(jar.ywguid || jar.gwguid || jar.guid)
}
function notify(title, sub, msg) {
$notify(title, sub || '', msg || '')
+8 -2
View File
@@ -39,9 +39,15 @@ function run({ cookie = '', body = '' }) {
{
const notices = run({
cookie: 'cmfuToken=abc; QDH=def',
body: JSON.stringify({ Data: { UserInfo: { UserId: 2468 } } }),
body: JSON.stringify({ Data: { UserInfo: { UserId: 24680 } } }),
});
assert.equal(notices[0][1], '抓取成功 uid:2468');
assert.equal(notices[0][1], '抓取成功 uid:24680');
}
{
const qdheader = Buffer.from('(null)|(null)|1179|2556|(null)|16.10|0|iOS/iPhone/(null)|0|(null)|(null)|475700975|1779006621000|0|(null)|||(null)|(null)|0').toString('base64').replace(/=+$/, '');
const notices = run({ cookie: `QDHeader=${qdheader}; ywguid=120098575768; QDH=abc` });
assert.equal(notices[0][1], '抓取成功 uid:120098575768');
}
{