mirror of
https://github.com/NeteaseCloudMusicApiEnhanced/api-enhanced.git
synced 2026-08-12 08:50:38 +00:00
feat: weapi支持checkToken
This commit is contained in:
parent
7822ab08d3
commit
4826c65042
@ -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
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user