From 656a69e07e3c853056c3ef186a3e58ec01dc2d02 Mon Sep 17 00:00:00 2001 From: overwriter <9856mmm@gmail.com> Date: Fri, 12 Jul 2024 23:24:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20eapi=E8=BF=94=E5=9B=9E=E5=80=BC?= =?UTF-8?q?=E5=8A=A0=E5=AF=86=E5=8F=AF=E8=A2=AB=E6=8E=A7=E5=88=B6=EF=BC=9B?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E4=B8=8D=E5=8A=A0=E5=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- util/config.json | 2 +- util/request.js | 28 ++++++++++++++++++++-------- 2 files changed, 21 insertions(+), 9 deletions(-) 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 }