diff --git a/CHANGELOG.MD b/CHANGELOG.MD index d01c9a22f17e653cfbee83d9fdf5a0c284d6cdbf..e20246b9d6a2905938d86a9d5a98c90462e2030d 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -1,4 +1,7 @@ # 更新日志 +### 4.0.6 | 2021.2.20 +- 修复 eapi 接口无法正确解密response的问题 [#1138](https://github.com/Binaryify/NeteaseCloudMusicApi/issues/1138) + ### 4.0.5 | 2021.2.19 - 修复红心接口默认不红心的问题 [#1126](https://github.com/Binaryify/NeteaseCloudMusicApi/issues/1126) diff --git a/package.json b/package.json index 27e051828a5b822d9c5dad5e5920b415a2073897..87069b5dd9e6f613266e6cce39404955cd5eff1a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "NeteaseCloudMusicApi", - "version": "4.0.5", + "version": "4.0.6", "description": "网易云音乐 NodeJS 版 API", "scripts": { "start": "node app.js", diff --git a/util/request.js b/util/request.js index 0ad3b550c0b8e01fadf9ef7f8f3c8fb6b038916a..b15d694b077ca704b3bc56c09dbee4da09007f63 100644 --- a/util/request.js +++ b/util/request.js @@ -111,7 +111,7 @@ const createRequest = (method, url, data, options) => { } const answer = { status: 500, body: {}, cookie: [] } - const settings = { + let settings = { method: method, url: url, headers: headers, @@ -143,7 +143,12 @@ const createRequest = (method, url, data, options) => { } } } - + if (options.crypto === 'eapi') { + settings = { + ...settings, + responseType: 'arraybuffer', + } + } axios(settings) .then((res) => { const body = res.data @@ -151,7 +156,12 @@ const createRequest = (method, url, data, options) => { x.replace(/\s*Domain=[^(;|$)]+;*/, ''), ) try { - answer.body = body + if (options.crypto === 'eapi') { + answer.body = JSON.parse(encrypt.decrypt(body).toString()) + } else { + answer.body = body + } + answer.status = answer.body.code || res.status if ( [201, 302, 400, 502, 800, 801, 802, 803].indexOf(answer.body.code) > @@ -161,6 +171,7 @@ const createRequest = (method, url, data, options) => { answer.status = 200 } } catch (e) { + // console.log(e) answer.body = body answer.status = res.status }