diff --git a/module/register_checktoken_v2.js b/module/register_checktoken_v2.js index f2b47aa..86faf23 100644 --- a/module/register_checktoken_v2.js +++ b/module/register_checktoken_v2.js @@ -34,5 +34,24 @@ module.exports = async (query) => { } } +// 模块加载时自动获取一次 Token,确保 request.js 使用时不为空 +fetch() + .then((token) => { + _token = token + }) + .catch(() => { + // 静默失败,后续请求时会重试 + }) + // 给 request.js 读取用 -module.exports.getToken = () => _token +module.exports.getToken = () => { + if (!_token) { + // 如果 Token 为空,异步触发获取 + fetch() + .then((token) => { + _token = token + }) + .catch(() => {}) + } + return _token +} diff --git a/util/request.js b/util/request.js index d9027f7..a009cdc 100644 --- a/util/request.js +++ b/util/request.js @@ -243,6 +243,9 @@ const createRequest = (uri, data, options) => { headers['Referer'] = options.domain || DOMAIN headers['User-Agent'] = options.ua || chooseUserAgent('weapi') data.csrf_token = csrfToken + if (options.checkToken) { + headers['X-antiCheatToken'] = token + } encryptData = encrypt.weapi(data) url = (options.domain || DOMAIN) + '/weapi/' + uri.substr(5) break