mirror of
https://github.com/NeteaseCloudMusicApiEnhanced/api-enhanced.git
synced 2026-10-20 14:41:23 +08:00
Merge pull request #276 from 1254qwer/fix/xeapi/csr
fix: xeapi 请求从 BSR 改为 CSR
This commit is contained in:
@@ -32,7 +32,7 @@ module.exports = async (query, request) => {
|
|||||||
|
|
||||||
const res = await axios({
|
const res = await axios({
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: APP_CONF.apiDomain + '/api/gorilla/anti/crawler/security/key/get',
|
url: APP_CONF.apiDomain + '/api/bsr/sk/get',
|
||||||
headers: {
|
headers: {
|
||||||
'User-Agent':
|
'User-Agent':
|
||||||
'NeteaseMusic/9.5.61.260802021928(9005061);Dalvik/2.1.0 (Linux; U; Android 12; HBN-AL00 Build/cd737a2.0)',
|
'NeteaseMusic/9.5.61.260802021928(9005061);Dalvik/2.1.0 (Linux; U; Android 12; HBN-AL00 Build/cd737a2.0)',
|
||||||
|
|||||||
+22
-6
@@ -206,9 +206,19 @@ const xeapiMidTransform = (ciphertext) => {
|
|||||||
for (let i = 0; i < ciphertext.length; i++) {
|
for (let i = 0; i < ciphertext.length; i++) {
|
||||||
xored[i] = ciphertext[i] ^ random[i & 0x0f]
|
xored[i] = ciphertext[i] ^ random[i & 0x0f]
|
||||||
}
|
}
|
||||||
const b64 = Buffer.from(xored.toString('base64'))
|
const rot = xored.length ? (random[0] & 0x0f) % xored.length : 0
|
||||||
const rot = b64.length ? (random[0] & 0x0f) % b64.length : 0
|
return Buffer.concat([random, xored.subarray(rot), xored.subarray(0, rot)])
|
||||||
return Buffer.concat([random, b64.subarray(rot), b64.subarray(0, rot)])
|
}
|
||||||
|
|
||||||
|
const decoder = new TextDecoder('utf-8', { fatal: true })
|
||||||
|
|
||||||
|
const isUtf8 = (buf) => {
|
||||||
|
try {
|
||||||
|
decoder.decode(buf)
|
||||||
|
return true
|
||||||
|
} catch {
|
||||||
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const xeapiEncryptS = (dynamicKey, publicKeyState, os) => {
|
const xeapiEncryptS = (dynamicKey, publicKeyState, os) => {
|
||||||
@@ -251,7 +261,13 @@ const buildXeapiPlaintext = (uri, data, options = {}) => {
|
|||||||
const bodyData = { ...data }
|
const bodyData = { ...data }
|
||||||
delete bodyData.e_r
|
delete bodyData.e_r
|
||||||
const body = Buffer.from(new URLSearchParams(bodyData).toString())
|
const body = Buffer.from(new URLSearchParams(bodyData).toString())
|
||||||
fields.body = body.toString('base64')
|
if (body.length) {
|
||||||
|
if (mediaType === 'application/x-www-form-urlencoded' && isUtf8(body)) {
|
||||||
|
fields.content = body.toString('utf8')
|
||||||
|
} else {
|
||||||
|
fields.body = body.toString('base64')
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fields.queryString) {
|
if (fields.queryString) {
|
||||||
@@ -274,7 +290,7 @@ const xeapi = (uri, data, options = {}) => {
|
|||||||
const dynamicKey = activeSessionKey || crypto.randomBytes(16)
|
const dynamicKey = activeSessionKey || crypto.randomBytes(16)
|
||||||
const plaintext = Buffer.from(buildXeapiPlaintext(uri, data, options))
|
const plaintext = Buffer.from(buildXeapiPlaintext(uri, data, options))
|
||||||
|
|
||||||
const b = aesEcbEncrypt(
|
const c = aesEcbEncrypt(
|
||||||
dynamicKey,
|
dynamicKey,
|
||||||
xeapiMidTransform(aesEcbEncrypt(xeapiStaticKey, plaintext)),
|
xeapiMidTransform(aesEcbEncrypt(xeapiStaticKey, plaintext)),
|
||||||
)
|
)
|
||||||
@@ -287,7 +303,7 @@ const xeapi = (uri, data, options = {}) => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
B: b.toString('base64'),
|
C: c.toString('base64url'),
|
||||||
S: s.toString('base64'),
|
S: s.toString('base64'),
|
||||||
R: r.toString('base64'),
|
R: r.toString('base64'),
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user