mirror of
https://github.com/NeteaseCloudMusicApiEnhanced/api-enhanced.git
synced 2026-10-20 14:41:23 +08:00
update 4.31.0
This commit is contained in:
+27
-9
@@ -1,5 +1,6 @@
|
||||
const CryptoJS = require('crypto-js')
|
||||
const forge = require('node-forge')
|
||||
const zlib = require('zlib')
|
||||
const iv = '0102030405060708'
|
||||
const presetKey = '0CoJUm6Qyw8W8jud'
|
||||
const linuxapiKey = 'rFgB&h#%2?^eDg:Q'
|
||||
@@ -44,7 +45,7 @@ const aesDecrypt = (ciphertext, key, iv, format = 'base64') => {
|
||||
},
|
||||
)
|
||||
}
|
||||
return bytes.toString(CryptoJS.enc.Utf8)
|
||||
return bytes
|
||||
}
|
||||
const rsaEncrypt = (str, key) => {
|
||||
const forgePublicKey = forge.pki.publicKeyFromPem(key)
|
||||
@@ -85,20 +86,37 @@ const eapi = (url, object) => {
|
||||
params: aesEncrypt(data, 'ecb', eapiKey, '', 'hex'),
|
||||
}
|
||||
}
|
||||
const eapiResDecrypt = (encryptedParams) => {
|
||||
const eapiResDecrypt = (encryptedParams, aeapi = false) => {
|
||||
// 使用aesDecrypt解密参数
|
||||
try {
|
||||
const decryptedData = aesDecrypt(encryptedParams, eapiKey, '', 'hex')
|
||||
return JSON.parse(decryptedData)
|
||||
const decrypted = aesDecrypt(encryptedParams, eapiKey, '', 'hex') // WordArray
|
||||
|
||||
if (aeapi) {
|
||||
// 带压缩的解密:先转 Base64 再解压
|
||||
const decryptedBuffer = Buffer.from(
|
||||
decrypted.toString(CryptoJS.enc.Base64),
|
||||
'base64',
|
||||
)
|
||||
const decompressed = zlib.gunzipSync(decryptedBuffer)
|
||||
return JSON.parse(decompressed.toString())
|
||||
} else {
|
||||
// 普通解密:直接转 UTF-8 字符串
|
||||
return JSON.parse(decrypted.toString(CryptoJS.enc.Utf8))
|
||||
}
|
||||
} catch (error) {
|
||||
console.log('eapiResDecrypt error:', error)
|
||||
console.log(`eapiResDecrypt error:`, error)
|
||||
return null
|
||||
}
|
||||
}
|
||||
const eapiReqDecrypt = (encryptedParams) => {
|
||||
// 使用aesDecrypt解密参数
|
||||
const decryptedData = aesDecrypt(encryptedParams, eapiKey, '', 'hex')
|
||||
// 使用正则表达式解析出URL和数据
|
||||
// 使用 aesDecrypt 解密参数
|
||||
const decryptedData = aesDecrypt(
|
||||
encryptedParams,
|
||||
eapiKey,
|
||||
'',
|
||||
'hex',
|
||||
).toString(CryptoJS.enc.Utf8)
|
||||
// 使用正则表达式解析出 URL 和数据
|
||||
const match = decryptedData.match(/(.*?)-36cd479b6b5-(.*?)-36cd479b6b5-(.*)/)
|
||||
if (match) {
|
||||
const url = match[1]
|
||||
@@ -106,7 +124,7 @@ const eapiReqDecrypt = (encryptedParams) => {
|
||||
return { url, data }
|
||||
}
|
||||
|
||||
// 如果没有匹配到,返回null
|
||||
// 如果没有匹配到,返回 null
|
||||
return null
|
||||
}
|
||||
const decrypt = (cipher) => {
|
||||
|
||||
+11
-10
@@ -188,6 +188,13 @@ const createRequest = (uri, data, options) => {
|
||||
|
||||
const answer = { status: 500, body: {}, cookie: [] }
|
||||
|
||||
data.e_r = toBoolean(
|
||||
options.e_r !== undefined
|
||||
? options.e_r
|
||||
: data.e_r !== undefined
|
||||
? data.e_r
|
||||
: ENCRYPT_RESPONSE,
|
||||
)
|
||||
// 根据加密方式处理
|
||||
switch (crypto) {
|
||||
case 'weapi':
|
||||
@@ -239,13 +246,6 @@ const createRequest = (uri, data, options) => {
|
||||
if (crypto === 'eapi') {
|
||||
// headers['x-aeapi'] = true // 服务器会使用gzip压缩返回值
|
||||
data.header = header
|
||||
data.e_r = toBoolean(
|
||||
options.e_r !== undefined
|
||||
? options.e_r
|
||||
: data.e_r !== undefined
|
||||
? data.e_r
|
||||
: ENCRYPT_RESPONSE,
|
||||
)
|
||||
encryptData = encrypt.eapi(uri, data)
|
||||
url = (options.domain || API_DOMAIN) + '/eapi/' + uri.substr(5)
|
||||
} else if (crypto === 'api') {
|
||||
@@ -269,8 +269,9 @@ const createRequest = (uri, data, options) => {
|
||||
httpsAgent: createHttpsAgent(),
|
||||
}
|
||||
|
||||
// e_r处理
|
||||
if (data.e_r) {
|
||||
// 使用返回值加密
|
||||
const use_e_r = (crypto === 'eapi' || crypto === 'weapi') && data.e_r
|
||||
if (use_e_r) {
|
||||
settings.encoding = null
|
||||
settings.responseType = 'arraybuffer'
|
||||
}
|
||||
@@ -318,7 +319,7 @@ const createRequest = (uri, data, options) => {
|
||||
)
|
||||
|
||||
try {
|
||||
if (crypto === 'eapi' && data.e_r) {
|
||||
if (use_e_r) {
|
||||
answer.body = encrypt.eapiResDecrypt(
|
||||
body.toString('hex').toUpperCase(),
|
||||
headers['x-aeapi'],
|
||||
|
||||
Reference in New Issue
Block a user