mirror of
https://github.com/NeteaseCloudMusicApiEnhanced/api-enhanced.git
synced 2025-10-22 22:53:09 +00:00
服务启动刷新游客cookie
This commit is contained in:
parent
9e5c9372fe
commit
b3ca43267a
@ -1,4 +1,7 @@
|
|||||||
# 更新日志
|
# 更新日志
|
||||||
|
### 4.6.1 | 2022.05.29
|
||||||
|
- 修复请求接口提示需要验证的问题,增加游客登录接口,服务启动更新游客cookie
|
||||||
|
|
||||||
### 4.6.0 | 2022.05.29
|
### 4.6.0 | 2022.05.29
|
||||||
- 修复请求接口提示需要验证的问题 [#1541](https://github.com/Binaryify/NeteaseCloudMusicApi/issues/1541)
|
- 修复请求接口提示需要验证的问题 [#1541](https://github.com/Binaryify/NeteaseCloudMusicApi/issues/1541)
|
||||||
|
|
||||||
|
11
app.js
11
app.js
@ -1,4 +1,9 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
require('./server').serveNcmApi({
|
const generateConfig = require('./generateConfig')
|
||||||
checkVersion: true,
|
async function start() {
|
||||||
})
|
await generateConfig()
|
||||||
|
require('./server').serveNcmApi({
|
||||||
|
checkVersion: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
start()
|
||||||
|
@ -523,6 +523,13 @@ v3.30.0 后支持手动传入 cookie,登录接口返回内容新增 `cookie` 字
|
|||||||
|
|
||||||
调用可参考项目文件例子`/public/qrlogin.html` (访问地址:http://localhost:3000/qrlogin.html)
|
调用可参考项目文件例子`/public/qrlogin.html` (访问地址:http://localhost:3000/qrlogin.html)
|
||||||
|
|
||||||
|
|
||||||
|
#### 3. 游客登录
|
||||||
|
说明 : 直接调用此接口, 可获取游客cookie,如果遇到其他接口未登录状态报400状态码需要验证的错误,可使用此接口获取游客cookie避免报错
|
||||||
|
|
||||||
|
**接口地址 :** `/register/anonimous`
|
||||||
|
|
||||||
|
|
||||||
#### 注意
|
#### 注意
|
||||||
|
|
||||||
调用登录接口的速度比调用其他接口慢 , 因为登录过程调用了加密算法
|
调用登录接口的速度比调用其他接口慢 , 因为登录过程调用了加密算法
|
||||||
|
24
generateConfig.js
Normal file
24
generateConfig.js
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
const fs = require('fs')
|
||||||
|
const { register_anonimous } = require('./main')
|
||||||
|
const { cookieToJson } = require('./util/index')
|
||||||
|
const config = require('./util/config.json')
|
||||||
|
|
||||||
|
async function generateConfig() {
|
||||||
|
try {
|
||||||
|
const res = await register_anonimous()
|
||||||
|
const cookie = res.body.cookie
|
||||||
|
if (cookie) {
|
||||||
|
const cookieObj = cookieToJson(cookie)
|
||||||
|
let newConfig = { ...config }
|
||||||
|
newConfig.anonymous_token = cookieObj.MUSIC_A
|
||||||
|
fs.writeFileSync(
|
||||||
|
'./util/config.json',
|
||||||
|
JSON.stringify(newConfig, null, 2),
|
||||||
|
'utf-8',
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
module.exports = generateConfig
|
2
main.js
2
main.js
@ -11,7 +11,7 @@ fs.readdirSync(path.join(__dirname, 'module'))
|
|||||||
if (!file.endsWith('.js')) return
|
if (!file.endsWith('.js')) return
|
||||||
let fileModule = require(path.join(__dirname, 'module', file))
|
let fileModule = require(path.join(__dirname, 'module', file))
|
||||||
let fn = file.split('.').shift() || ''
|
let fn = file.split('.').shift() || ''
|
||||||
obj[fn] = function (data) {
|
obj[fn] = function (data = {}) {
|
||||||
if (typeof data.cookie === 'string') {
|
if (typeof data.cookie === 'string') {
|
||||||
data.cookie = cookieToJson(data.cookie)
|
data.cookie = cookieToJson(data.cookie)
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
// 首页-发现 dragon ball
|
// 首页-发现 dragon ball
|
||||||
// 这个接口为移动端接口,首页-发现页(每日推荐、歌单、排行榜 那些入口)
|
// 这个接口为移动端接口,首页-发现页(每日推荐、歌单、排行榜 那些入口)
|
||||||
// 数据结构可以参考 https://github.com/hcanyz/flutter-netease-music-api/blob/master/lib/src/api/uncategorized/bean.dart#L290 HomeDragonBallWrap
|
// 数据结构可以参考 https://github.com/hcanyz/flutter-netease-music-api/blob/master/lib/src/api/uncategorized/bean.dart#L290 HomeDragonBallWrap
|
||||||
// !需要登录或者匿名登录,非登录返回 []
|
// !需要登录或者游客登录,非登录返回 []
|
||||||
const config = require('../util/config.json')
|
|
||||||
module.exports = (query, request) => {
|
module.exports = (query, request) => {
|
||||||
const data = {}
|
const data = {}
|
||||||
query.cookie.os = 'ios'
|
query.cookie.os = 'ios'
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "NeteaseCloudMusicApi",
|
"name": "NeteaseCloudMusicApi",
|
||||||
"version": "4.6.0",
|
"version": "4.6.1",
|
||||||
"description": "网易云音乐 NodeJS 版 API",
|
"description": "网易云音乐 NodeJS 版 API",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node app.js",
|
"start": "node app.js",
|
||||||
|
@ -43,7 +43,7 @@ const chooseUserAgent = (ua = false) => {
|
|||||||
? realUserAgentList[Math.floor(Math.random() * realUserAgentList.length)]
|
? realUserAgentList[Math.floor(Math.random() * realUserAgentList.length)]
|
||||||
: ua
|
: ua
|
||||||
}
|
}
|
||||||
const createRequest = (method, url, data, options) => {
|
const createRequest = (method, url, data = {}, options) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let headers = { 'User-Agent': chooseUserAgent(options.ua) }
|
let headers = { 'User-Agent': chooseUserAgent(options.ua) }
|
||||||
if (method.toUpperCase() === 'POST')
|
if (method.toUpperCase() === 'POST')
|
||||||
@ -54,7 +54,7 @@ const createRequest = (method, url, data, options) => {
|
|||||||
// headers['X-Real-IP'] = '118.88.88.88'
|
// headers['X-Real-IP'] = '118.88.88.88'
|
||||||
if (typeof options.cookie === 'object') {
|
if (typeof options.cookie === 'object') {
|
||||||
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 = config.anonymous_token
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user