diff --git a/util/config.json b/util/config.json index 33de888..3dbfad1 100644 --- a/util/config.json +++ b/util/config.json @@ -13,6 +13,6 @@ "apiDomain": "https://interface.music.163.com", "domain": "https://music.163.com", "encrypt": true, - "encryptResponse": true + "encryptResponse": false } } \ No newline at end of file diff --git a/util/request.js b/util/request.js index 15f2491..10b5997 100644 --- a/util/request.js +++ b/util/request.js @@ -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 }