mirror of
https://gitlab.com/Binaryify/neteasecloudmusicapi.git
synced 2025-05-23 22:37:41 +08:00
update: anonymous_token配置抽离, 生成稳定性问题修复
This commit is contained in:
parent
6741d9a920
commit
52c6021d89
1
.gitignore
vendored
1
.gitignore
vendored
@ -6,3 +6,4 @@ node_modules
|
|||||||
.history
|
.history
|
||||||
examples/moddef.json
|
examples/moddef.json
|
||||||
bin
|
bin
|
||||||
|
anonymous_token
|
||||||
|
@ -1,4 +1,9 @@
|
|||||||
# 更新日志
|
# 更新日志
|
||||||
|
### 4.11.1 | 2023.09.08
|
||||||
|
- `anonymous_token` 配置抽离
|
||||||
|
|
||||||
|
- `anonymous_token` 生成稳定性问题修复
|
||||||
|
|
||||||
### 4.11.0 | 2023.09.07
|
### 4.11.0 | 2023.09.07
|
||||||
- 新增 `播客搜索`,`播客上传声音`接口 #1789
|
- 新增 `播客搜索`,`播客上传声音`接口 #1789
|
||||||
|
|
||||||
|
9
app.js
9
app.js
@ -1,6 +1,13 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
const generateConfig = require('./generateConfig')
|
const fs = require('fs')
|
||||||
|
const path = require('path')
|
||||||
|
|
||||||
async function start() {
|
async function start() {
|
||||||
|
// 检测是否存在 anonymous_token 文件,没有则生成
|
||||||
|
if (!fs.existsSync('./anonymous_token')) {
|
||||||
|
fs.writeFileSync(path.resolve(__dirname, 'anonymous_token'), '', 'utf-8')
|
||||||
|
}
|
||||||
|
const generateConfig = require('./generateConfig')
|
||||||
await generateConfig()
|
await generateConfig()
|
||||||
require('./server').serveNcmApi({
|
require('./server').serveNcmApi({
|
||||||
checkVersion: true,
|
checkVersion: true,
|
||||||
|
@ -272,6 +272,8 @@
|
|||||||
254. 回忆坐标
|
254. 回忆坐标
|
||||||
255. 播客搜索
|
255. 播客搜索
|
||||||
256. 播客声音上传
|
256. 播客声音上传
|
||||||
|
257. 验证接口-二维码生成
|
||||||
|
258. 验证接口-二维码检测
|
||||||
|
|
||||||
## 安装
|
## 安装
|
||||||
|
|
||||||
@ -4229,6 +4231,7 @@ type='1009' 获取其 id, 如`/search?keywords= 代码时间 &type=1009`
|
|||||||
|
|
||||||
**必选参数:**
|
**必选参数:**
|
||||||
`qr`: `/verify/getQr`接口返回的`qr`字符串
|
`qr`: `/verify/getQr`接口返回的`qr`字符串
|
||||||
|
|
||||||
## 离线访问此文档
|
## 离线访问此文档
|
||||||
|
|
||||||
此文档同时也是 Progressive Web Apps(PWA), 加入了 serviceWorker, 可离线访问
|
此文档同时也是 Progressive Web Apps(PWA), 加入了 serviceWorker, 可离线访问
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const { register_anonimous } = require('./main')
|
const { register_anonimous } = require('./main')
|
||||||
const { cookieToJson } = require('./util/index')
|
const { cookieToJson } = require('./util/index')
|
||||||
const config = require('./util/config.json')
|
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
async function generateConfig() {
|
async function generateConfig() {
|
||||||
try {
|
try {
|
||||||
@ -9,11 +8,9 @@ async function generateConfig() {
|
|||||||
const cookie = res.body.cookie
|
const cookie = res.body.cookie
|
||||||
if (cookie) {
|
if (cookie) {
|
||||||
const cookieObj = cookieToJson(cookie)
|
const cookieObj = cookieToJson(cookie)
|
||||||
let newConfig = { ...config }
|
|
||||||
newConfig.anonymous_token = cookieObj.MUSIC_A
|
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
path.resolve(__dirname, 'util/config.json'),
|
path.resolve(__dirname, 'anonymous_token'),
|
||||||
JSON.stringify(newConfig, null, 2),
|
cookieObj.MUSIC_A,
|
||||||
'utf-8',
|
'utf-8',
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -11,17 +11,10 @@ function cloudmusic_dll_encode_id(some_id) {
|
|||||||
const digest = crypto.createHash('md5').update(xored).digest()
|
const digest = crypto.createHash('md5').update(xored).digest()
|
||||||
return digest.toString('base64')
|
return digest.toString('base64')
|
||||||
}
|
}
|
||||||
function createRandomDeviceId() {
|
|
||||||
const t = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
|
|
||||||
const e = 6
|
|
||||||
let n = ''
|
|
||||||
for (let i = 0; i < e; i++) n += t.charAt(Math.floor(Math.random() * e))
|
|
||||||
return n
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = async (query, request) => {
|
module.exports = async (query, request) => {
|
||||||
query.cookie.os = 'iOS'
|
query.cookie.os = 'iOS'
|
||||||
const deviceId = createRandomDeviceId()
|
const deviceId = `NMUSIC`
|
||||||
const encodedId = Buffer.from(
|
const encodedId = Buffer.from(
|
||||||
`${deviceId} ${cloudmusic_dll_encode_id(deviceId)}`,
|
`${deviceId} ${cloudmusic_dll_encode_id(deviceId)}`,
|
||||||
)
|
)
|
||||||
@ -41,7 +34,6 @@ module.exports = async (query, request) => {
|
|||||||
realIP: query.realIP,
|
realIP: query.realIP,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
if (result.body.code === 200) {
|
if (result.body.code === 200) {
|
||||||
result = {
|
result = {
|
||||||
status: 200,
|
status: 200,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "NeteaseCloudMusicApi",
|
"name": "NeteaseCloudMusicApi",
|
||||||
"version": "4.11.0",
|
"version": "4.11.1",
|
||||||
"description": "网易云音乐 NodeJS 版 API",
|
"description": "网易云音乐 NodeJS 版 API",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node app.js",
|
"start": "node app.js",
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
{
|
{
|
||||||
"anonymous_token": "de91e1f8119d32e01cc73efcb82c0a30c9137e8d4f88dbf5e3d7bf3f28998f21add2bc8204eeee5e56c0bbb8743574b46ca2c10c35dc172199bef9bf4d60ecdeab066bb4dc737d1c3324751bcc9aaf44c3061cd18d77b7a0",
|
|
||||||
"resourceTypeMap": {
|
"resourceTypeMap": {
|
||||||
"0": "R_SO_4_",
|
"0": "R_SO_4_",
|
||||||
"1": "R_MV_5_",
|
"1": "R_MV_5_",
|
||||||
|
@ -5,8 +5,10 @@ const { PacProxyAgent } = require('pac-proxy-agent')
|
|||||||
const http = require('http')
|
const http = require('http')
|
||||||
const https = require('https')
|
const https = require('https')
|
||||||
const tunnel = require('tunnel')
|
const tunnel = require('tunnel')
|
||||||
|
const fs = require('fs')
|
||||||
|
const anonymous_token = fs.readFileSync('./anonymous_token', 'utf-8')
|
||||||
|
console.log(anonymous_token)
|
||||||
const { URLSearchParams, URL } = require('url')
|
const { URLSearchParams, URL } = require('url')
|
||||||
const config = require('../util/config.json')
|
|
||||||
// request.debug = true // 开启可看到更详细信息
|
// request.debug = true // 开启可看到更详细信息
|
||||||
|
|
||||||
const chooseUserAgent = (ua = false) => {
|
const chooseUserAgent = (ua = false) => {
|
||||||
@ -72,7 +74,7 @@ const createRequest = (method, url, data = {}, options) => {
|
|||||||
if (!options.cookie.MUSIC_U) {
|
if (!options.cookie.MUSIC_U) {
|
||||||
// 游客
|
// 游客
|
||||||
if (!options.cookie.MUSIC_A) {
|
if (!options.cookie.MUSIC_A) {
|
||||||
options.cookie.MUSIC_A = config.anonymous_token
|
options.cookie.MUSIC_A = anonymous_token
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
headers['Cookie'] = Object.keys(options.cookie)
|
headers['Cookie'] = Object.keys(options.cookie)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user