fix: align pingme capture with working ck format
This commit is contained in:
+26
-64
@@ -4,11 +4,10 @@
|
||||
* 订阅地址:
|
||||
* https://gitea.chickliu.fun/Hermes/qx/raw/branch/main/conf/pingme.conf
|
||||
*
|
||||
* 功能:
|
||||
* - 监听 api.pingmeapp.net/app/queryBalanceAndBonus、checkIn、videoBonus
|
||||
* - 抓取 pingme_multi.js 需要的 url / paramsRaw / headers
|
||||
* - 弹窗输出可直接追加到 NiuPanel /app/data/scripts/pingme_ck.json 的 JSON 对象
|
||||
* 输出格式严格对齐当前 NiuPanel 正确 CK:
|
||||
* {"url":"https://api.pingmeapp.net/app/queryBalanceAndBonus?...","headers":{...}}
|
||||
*
|
||||
* 注意:pingme_multi.js 会从 url 自行解析查询参数并重算 sign,正确 CK 不需要 paramsRaw。
|
||||
* 安全:不上传 CK,不请求第三方;仅在 QX 本地保存最近一次抓取结果。
|
||||
*/
|
||||
|
||||
@@ -34,72 +33,30 @@ function getHeader(headers, name) {
|
||||
return ''
|
||||
}
|
||||
|
||||
function parseRawQuery(url) {
|
||||
const raw = String(url || '')
|
||||
const qIndex = raw.indexOf('?')
|
||||
if (qIndex < 0) return {}
|
||||
const hashIndex = raw.indexOf('#', qIndex + 1)
|
||||
const query = raw.slice(qIndex + 1, hashIndex >= 0 ? hashIndex : undefined)
|
||||
const out = {}
|
||||
query.split('&').forEach(pair => {
|
||||
if (!pair) return
|
||||
const idx = pair.indexOf('=')
|
||||
if (idx < 0) return
|
||||
const k = pair.slice(0, idx)
|
||||
const v = pair.slice(idx + 1)
|
||||
if (k) out[k] = v
|
||||
})
|
||||
return out
|
||||
function hasQuery(url) {
|
||||
return String(url || '').indexOf('?') >= 0 && String(url || '').split('?')[1].length > 0
|
||||
}
|
||||
|
||||
function pickHeaders(headers) {
|
||||
const names = [
|
||||
'User-Agent',
|
||||
'Accept',
|
||||
'Accept-Language',
|
||||
'Authorization',
|
||||
'Cookie',
|
||||
'X-Requested-With',
|
||||
'Content-Type',
|
||||
'Origin',
|
||||
'Referer'
|
||||
]
|
||||
function buildHeaders(headers) {
|
||||
// 严格按现有正确 pingme_ck.json 的 header 形状输出。
|
||||
// 保留 Host/Connection/Accept-Encoding,因为当前正确 CK 就是这个集合;
|
||||
// pingme_multi.js 后续会覆盖 Host 与 Accept-Encoding,不会影响执行。
|
||||
const ordered = ['Host', 'Connection', 'Accept', 'User-Agent', 'Accept-Language', 'Accept-Encoding']
|
||||
const out = {}
|
||||
names.forEach(name => {
|
||||
ordered.forEach(name => {
|
||||
const v = getHeader(headers, name)
|
||||
if (v !== undefined && v !== null && String(v) !== '') out[name] = String(v)
|
||||
})
|
||||
|
||||
// 保留 PingMe/客户端自定义头,避免后续接口校验客户端参数。
|
||||
Object.keys(headers || {}).forEach(k => {
|
||||
const lk = String(k).toLowerCase()
|
||||
if (
|
||||
lk.startsWith('x-') ||
|
||||
lk.indexOf('device') >= 0 ||
|
||||
lk.indexOf('token') >= 0 ||
|
||||
lk.indexOf('client') >= 0 ||
|
||||
lk.indexOf('app') >= 0
|
||||
) {
|
||||
if (!/^content-length$/i.test(k) && !/^host$/i.test(k)) out[k] = String(headers[k])
|
||||
}
|
||||
})
|
||||
if (!out.Host) out.Host = 'api.pingmeapp.net'
|
||||
if (!out.Accept) out.Accept = '*/*'
|
||||
return out
|
||||
}
|
||||
|
||||
function buildRecord(req) {
|
||||
const url = String(req.url || '')
|
||||
const paramsRaw = parseRawQuery(url)
|
||||
const headers = pickHeaders(req.headers || {})
|
||||
return { url, paramsRaw, headers }
|
||||
}
|
||||
|
||||
function hasRequiredParams(record) {
|
||||
const p = record && record.paramsRaw || {}
|
||||
return Object.keys(p).length > 0
|
||||
}
|
||||
|
||||
function formatRecord(record) {
|
||||
return JSON.stringify(record)
|
||||
return {
|
||||
url: String(req.url || ''),
|
||||
headers: buildHeaders(req.headers || {})
|
||||
}
|
||||
}
|
||||
|
||||
function main() {
|
||||
@@ -109,13 +66,18 @@ function main() {
|
||||
return done()
|
||||
}
|
||||
|
||||
const record = buildRecord(req)
|
||||
if (!hasRequiredParams(record)) {
|
||||
notify('抓取失败', '当前请求缺少 URL 查询参数,请打开 PingMe 触发余额/签到/视频接口')
|
||||
const url = String(req.url || '')
|
||||
if (!/^https?:\/\/api\.pingmeapp\.net\/app\/queryBalanceAndBonus(?:\?|$)/.test(url)) {
|
||||
notify('等待正确接口', '请打开 PingMe 触发 queryBalanceAndBonus 接口')
|
||||
return done()
|
||||
}
|
||||
if (!hasQuery(url)) {
|
||||
notify('抓取失败', 'queryBalanceAndBonus 请求缺少查询参数')
|
||||
return done()
|
||||
}
|
||||
|
||||
const text = formatRecord(record)
|
||||
const record = buildRecord(req)
|
||||
const text = JSON.stringify(record)
|
||||
setPref('pingme_ck_last', text)
|
||||
notify('CK 获取成功', text)
|
||||
done()
|
||||
|
||||
Reference in New Issue
Block a user