From 2fa78c38266e164aa17d183871e7cffe807e1ac0 Mon Sep 17 00:00:00 2001 From: MoeFurina Date: Fri, 17 Jul 2026 20:11:20 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=AF=84=E8=AE=BA?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- module/ad_get.js | 2 +- module/ad_listening_rights_gain.js | 2 +- module/comment.js | 2 +- module/playlist_subscribe.js | 2 +- module/register_checktoken_v2.js | 38 +++++++++++++++++++ ...hecktoken.js => register_checktoken_v3.js} | 2 +- public/free_listen.html | 2 +- public/yidun.html | 2 +- util/config.json | 3 +- util/request.js | 17 ++++++++- 10 files changed, 62 insertions(+), 10 deletions(-) create mode 100644 module/register_checktoken_v2.js rename module/{register_checktoken.js => register_checktoken_v3.js} (94%) diff --git a/module/ad_get.js b/module/ad_get.js index d288b5f..8d3c48b 100644 --- a/module/ad_get.js +++ b/module/ad_get.js @@ -8,7 +8,7 @@ module.exports = async (query, request) => { } const option = createOption(query, 'xeapi') - option.checkToken = true + option.checkToken = 'v2' const res = await request(`/api/ad/get`, data, option) const raw = res.body diff --git a/module/ad_listening_rights_gain.js b/module/ad_listening_rights_gain.js index 0009f90..e65c046 100644 --- a/module/ad_listening_rights_gain.js +++ b/module/ad_listening_rights_gain.js @@ -75,7 +75,7 @@ module.exports = async (query, request) => { const res = await request( `/api/ad/listening/rights/gain`, data, - createOption(query, 'xeapi', true), + createOption(query, 'eapi', 'v2'), ) return { diff --git a/module/comment.js b/module/comment.js index 8fa6eb4..c12f5d0 100644 --- a/module/comment.js +++ b/module/comment.js @@ -25,6 +25,6 @@ module.exports = (query, request) => { return request( `/api/resource/comments/${query.t}`, data, - createOption(query, 'weapi'), + createOption(query, 'xeapi', 'v3'), ) } diff --git a/module/playlist_subscribe.js b/module/playlist_subscribe.js index 062027f..2ab3975 100644 --- a/module/playlist_subscribe.js +++ b/module/playlist_subscribe.js @@ -9,6 +9,6 @@ module.exports = (query, request) => { ? { checkToken: query.checkToken || APP_CONF.checkToken } : {}), } - query.checkToken = true // 强制开启checkToken + query.checkToken = 'v2' // 强制开启checkToken return request(`/api/playlist/${path}`, data, createOption(query, 'eapi')) } diff --git a/module/register_checktoken_v2.js b/module/register_checktoken_v2.js new file mode 100644 index 0000000..f2b47aa --- /dev/null +++ b/module/register_checktoken_v2.js @@ -0,0 +1,38 @@ +// 易盾反作弊 Token 注册端点 +// 调用后获取实时 token 并存入共享存储,供后续带 checkToken 的请求使用 +// +// GET /register/checktoken → 返回当前 token(尚无则自动获取) +// POST /register/checktoken → 强制刷新 token +// GET /register/checktoken?refresh=1 → 强制刷新 +// +const { default: axios } = require('axios') +const { APP_CONF } = require('../util/config.json') + +const URL = APP_CONF.dunDomainV2 + '/v2/config/js?pn=YD00000558929251' +let _token = '' + +async function fetch() { + const res = await axios.get(URL, { timeout: 10000 }) + const data = res.data + if (data && data.code === 200 && data.result && data.result.conf) { + return data.result.conf + } + throw new Error('易盾返回异常: ' + JSON.stringify(data).substring(0, 200)) +} + +// 端点处理 +module.exports = async (query) => { + const refresh = query.refresh === '1' || query.refresh === 'true' + let token = refresh ? null : _token + if (!token) { + token = await fetch() + _token = token + } + return { + status: 200, + body: { code: 200, token, registered: !!token }, + } +} + +// 给 request.js 读取用 +module.exports.getToken = () => _token diff --git a/module/register_checktoken.js b/module/register_checktoken_v3.js similarity index 94% rename from module/register_checktoken.js rename to module/register_checktoken_v3.js index 095da6d..66b28a2 100644 --- a/module/register_checktoken.js +++ b/module/register_checktoken_v3.js @@ -8,7 +8,7 @@ const { default: axios } = require('axios') const { APP_CONF } = require('../util/config.json') -const URL = APP_CONF.dunDomain + '/v3/b?pn=YD00000558929251' +const URL = APP_CONF.dunDomainV3 + '/v3/b?pn=YD00000558929251' let _token = '' async function fetch() { diff --git a/public/free_listen.html b/public/free_listen.html index 7e3f894..1cfe4ff 100644 --- a/public/free_listen.html +++ b/public/free_listen.html @@ -172,7 +172,7 @@ setTag('s1tag', 'busy', '注册中…') setNum('s1num', false) try { - const res = await fetch(nocache(base + '/register/checktoken?refresh=1')) + const res = await fetch(nocache(base + '/register/checktoken/v2?refresh=1')) const data = await res.json() $('s1pre').textContent = JSON.stringify(data, null, 2) if (data.token) { diff --git a/public/yidun.html b/public/yidun.html index ab9b208..232b770 100644 --- a/public/yidun.html +++ b/public/yidun.html @@ -88,7 +88,7 @@ tag.textContent = '获取中…' try { - const url = base + '/register/checktoken' + (refresh ? '?refresh=1' : '') + const url = base + '/register/checktoken/v2' + (refresh ? '?refresh=1' : '') const res = await fetch(url) const data = await res.json() $('respDisplay').textContent = JSON.stringify(data, null, 2) diff --git a/util/config.json b/util/config.json index 08cd498..83376c9 100644 --- a/util/config.json +++ b/util/config.json @@ -15,7 +15,8 @@ "domain": "https://music.163.com", "clDomian": "https://clientlog.music.163.com", "clDomian3": "https://clientlog3.music.163.com", - "dunDomain": "https://ac.dun.163yun.com", + "dunDomainV3": "https://ac.dun.163yun.com", + "dunDomainV2": "https://ac.dun.163.com", "encrypt": true, "encryptResponse": false, "clientSign": "18:C0:4D:B9:8F:FE@@@453832335F384641365F424635335F303030315F303031425F343434415F343643365F333638332@@@@@@6ff673ef74955b38bce2fa8562d95c976ed4758b1227c4e9ee345987cee17bc9", diff --git a/util/request.js b/util/request.js index 4bf9b38..f47eeb4 100644 --- a/util/request.js +++ b/util/request.js @@ -18,7 +18,12 @@ const { } = require('./index') const { URLSearchParams, URL } = require('url') const { APP_CONF } = require('../util/config.json') -const { getToken: antiCheatToken } = require('../module/register_checktoken') +const { + getToken: antiCheatTokenV2, +} = require('../module/register_checktoken_v2') +const { + getToken: antiCheatTokenV3, +} = require('../module/register_checktoken_v3') // 预先读取匿名token并缓存 const anonymous_token = fs.readFileSync( @@ -182,7 +187,15 @@ const generateRequestId = () => { } const createRequest = (uri, data, options) => { - const token = options.checkToken ? antiCheatToken() : '' + let token = '' + switch (options.checkToken) { + case 'v2': + token = antiCheatTokenV2() + break + case 'v3': + token = antiCheatTokenV3() + break + } return new Promise((resolve, reject) => { // 变量声明和初始化