feat: weapi支持checkToken

This commit is contained in:
ElyPrism 2026-07-22 19:40:12 +08:00
parent 7822ab08d3
commit 4826c65042
No known key found for this signature in database
2 changed files with 23 additions and 1 deletions

View File

@ -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
}

View File

@ -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