Skip to content

Commit d0935f6

Browse files
committed
feat: add xeapi support and refactor eapi_decrypt to api_decrypt
- Added xeapi option to the API selection dropdown in api.html. - Removed eapi_decrypt.html and created a new api_decrypt.html for unified API decryption. - Implemented multi-crypto support in api_decrypt.html with corresponding UI changes. - Created decrypt.js module to handle decryption logic for different crypto types including xeapi. - Updated request.js to remove unnecessary debug logs and improve code clarity. - Updated index.html to link to the new api_decrypt.html instead of the removed eapi_decrypt.html.
1 parent 3e0337a commit d0935f6

10 files changed

Lines changed: 950 additions & 411 deletions

File tree

module/decrypt.js

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
const {
2+
eapiResDecrypt,
3+
eapiReqDecrypt,
4+
aesDecrypt,
5+
xeapiResDecrypt,
6+
} = require('../util/crypto')
7+
const CryptoJS = require('crypto-js')
8+
9+
const linuxapiKey = 'rFgB&h#%2?^eDg:Q'
10+
11+
module.exports = async (query, request) => {
12+
const crypto = query.crypto || 'eapi'
13+
const data = query.data || query.hexString || ''
14+
const isReq = query.isReq !== 'false'
15+
16+
if (!data) {
17+
return {
18+
status: 400,
19+
body: { code: 400, message: 'data is required' },
20+
}
21+
}
22+
23+
try {
24+
let result
25+
switch (crypto) {
26+
case 'eapi': {
27+
const pureHex = data.replace(/\s/g, '')
28+
result = isReq ? eapiReqDecrypt(pureHex) : eapiResDecrypt(pureHex)
29+
break
30+
}
31+
32+
case 'weapi': {
33+
if (isReq) {
34+
return {
35+
status: 400,
36+
body: {
37+
code: 400,
38+
message:
39+
'weapi 请求解密需要 RSA 私钥,暂不支持;仅支持 weapi 返回数据解密(e_r=true 时与 eapi 相同)',
40+
},
41+
}
42+
}
43+
const pureHex = data.replace(/\s/g, '')
44+
result = eapiResDecrypt(pureHex)
45+
break
46+
}
47+
48+
case 'linuxapi': {
49+
if (isReq) {
50+
const pureHex = data.replace(/\s/g, '')
51+
const decrypted = aesDecrypt(pureHex, linuxapiKey, '', 'hex')
52+
result = JSON.parse(decrypted.toString(CryptoJS.enc.Utf8))
53+
} else {
54+
result = typeof data === 'string' ? JSON.parse(data) : data
55+
}
56+
break
57+
}
58+
59+
case 'xeapi': {
60+
if (isReq) {
61+
return {
62+
status: 400,
63+
body: {
64+
code: 400,
65+
message:
66+
'xeapi 请求解密涉及 X25519 ECDH 密钥交换,流程复杂,暂不支持;仅支持 xeapi 返回数据解密',
67+
},
68+
}
69+
}
70+
const buf = Buffer.from(data, 'base64')
71+
result = xeapiResDecrypt(buf)
72+
break
73+
}
74+
75+
case 'api': {
76+
result = typeof data === 'string' ? JSON.parse(data) : data
77+
break
78+
}
79+
80+
default:
81+
return {
82+
status: 400,
83+
body: { code: 400, message: `未知加密方式: ${crypto}` },
84+
}
85+
}
86+
87+
return {
88+
status: 200,
89+
body: { code: 200, data: result },
90+
}
91+
} catch (error) {
92+
return {
93+
status: 400,
94+
body: { code: 400, message: `解密失败: ${error.message}` },
95+
}
96+
}
97+
}

module/song_url_v1.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,9 @@ module.exports = async (query, request) => {
5353
if (data.level == 'sky') {
5454
data.immerseType = 'c51'
5555
}
56-
return request(`/api/song/enhance/player/url/v1`, data, createOption(query))
56+
return request(
57+
`/api/song/enhance/player/url/v1`,
58+
data,
59+
createOption(query, 'xeapi'),
60+
)
5761
}

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@neteasecloudmusicapienhanced/api",
3-
"version": "4.33.1",
3+
"version": "4.34.0",
44
"description": "全网最全的网易云音乐API接口 || A revival project for NeteaseCloudMusicApi Node.js Services (Half Refactor & Enhanced) || 网易云音乐 API 备份 + 增强 || 本项目自原版v4.28.0版本后开始自行维护",
55
"scripts": {
66
"dev": "nodemon app.js",
@@ -65,7 +65,7 @@
6565
"data"
6666
],
6767
"dependencies": {
68-
"@neteasecloudmusicapienhanced/unblockmusic-utils": "^0.3.1",
68+
"@neteasecloudmusicapienhanced/unblockmusic-utils": "^0.3.2",
6969
"axios": "^1.16.1",
7070
"crypto-js": "^4.2.0",
7171
"dotenv": "^17.4.2",
@@ -88,12 +88,12 @@
8888
"@types/express-fileupload": "^1.5.1",
8989
"@types/mocha": "^10.0.10",
9090
"@types/node": "25.5.0",
91-
"@typescript-eslint/eslint-plugin": "^8.59.4",
92-
"@typescript-eslint/parser": "^8.59.4",
91+
"@typescript-eslint/eslint-plugin": "^8.60.0",
92+
"@typescript-eslint/parser": "^8.60.0",
9393
"eslint": "^9.39.4",
9494
"eslint-config-prettier": "^10.1.8",
9595
"eslint-plugin-html": "^8.1.4",
96-
"eslint-plugin-prettier": "^5.5.5",
96+
"eslint-plugin-prettier": "^5.5.6",
9797
"globals": "^17.6.0",
9898
"husky": "^9.1.7",
9999
"intelli-espower-loader": "^1.1.0",

0 commit comments

Comments
 (0)