mirror of
https://gitlab.com/Binaryify/neteasecloudmusicapi.git
synced 2025-05-23 22:37:41 +08:00
feat: eapi返回值加密可被控制;默认不加密
This commit is contained in:
parent
f7132eba63
commit
656a69e07e
@ -13,6 +13,6 @@
|
||||
"apiDomain": "https://interface.music.163.com",
|
||||
"domain": "https://music.163.com",
|
||||
"encrypt": true,
|
||||
"encryptResponse": true
|
||||
"encryptResponse": false
|
||||
}
|
||||
}
|
@ -140,6 +140,7 @@ const createRequest = (method, uri, data = {}, options) => {
|
||||
data.header = header
|
||||
encryptData = encrypt.eapi(uri, data)
|
||||
url = APP_CONF.apiDomain + '/eapi/' + uri.substr(5)
|
||||
data.e_r = data.e_r != undefined ? data.e_r : APP_CONF.encryptResponse // 用于加密eapi接口的返回值
|
||||
}
|
||||
if (options.crypto === 'eapi') {
|
||||
eapiEncrypt()
|
||||
@ -170,6 +171,14 @@ const createRequest = (method, uri, data = {}, options) => {
|
||||
httpsAgent: new https.Agent({ keepAlive: true }),
|
||||
}
|
||||
|
||||
if (data.e_r) {
|
||||
settings = {
|
||||
...settings,
|
||||
encoding: null,
|
||||
responseType: 'arraybuffer',
|
||||
}
|
||||
}
|
||||
|
||||
if (options.proxy) {
|
||||
if (options.proxy.indexOf('pac') > -1) {
|
||||
settings.httpAgent = new PacProxyAgent(options.proxy)
|
||||
@ -206,7 +215,15 @@ const createRequest = (method, uri, data = {}, options) => {
|
||||
x.replace(/\s*Domain=[^(;|$)]+;*/, ''),
|
||||
)
|
||||
try {
|
||||
answer.body = JSON.parse(body.toString())
|
||||
if (data.e_r) {
|
||||
// eapi接口返回值被加密
|
||||
answer.body = encrypt.eapiResDecrypt(
|
||||
body.toString('hex').toUpperCase(),
|
||||
)
|
||||
} else {
|
||||
answer.body = JSON.parse(body.toString())
|
||||
}
|
||||
|
||||
if (answer.body.code) {
|
||||
answer.body.code = Number(answer.body.code)
|
||||
}
|
||||
@ -221,13 +238,8 @@ const createRequest = (method, uri, data = {}, options) => {
|
||||
}
|
||||
} catch (e) {
|
||||
// console.log(e)
|
||||
try {
|
||||
answer.body = JSON.parse(encrypt.decrypt(body))
|
||||
} catch (err) {
|
||||
// console.log(err)
|
||||
// can't decrypt and can't parse directly
|
||||
answer.body = body
|
||||
}
|
||||
// can't decrypt and can't parse directly
|
||||
answer.body = body
|
||||
answer.status = res.status
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user