mirror of
https://gitlab.com/Binaryify/neteasecloudmusicapi.git
synced 2025-05-23 22:37:41 +08:00
登录接口返回内容增加cookie字段,支持手动传入cookie
This commit is contained in:
parent
96d0898ca1
commit
e9fe4351b4
@ -1,4 +1,7 @@
|
||||
# 更新日志
|
||||
### 3.30.0 | 2020.05.17
|
||||
- 登录接口返回内容增加`cookie`字段,支持手动传入cookie
|
||||
|
||||
### 3.29.1 | 2020.05.13
|
||||
- 调整通知接口分页参数 [#761](https://github.com/Binaryify/NeteaseCloudMusicApi/issues/761)
|
||||
|
||||
|
2
app.js
2
app.js
@ -66,7 +66,7 @@ fs.readdirSync(path.join(__dirname, 'module')).reverse().forEach(file => {
|
||||
let question = require(path.join(__dirname, 'module', file))
|
||||
|
||||
app.use(route, (req, res) => {
|
||||
let query = Object.assign({}, req.query, req.body, {cookie: req.cookies})
|
||||
let query = Object.assign({}, {cookie: req.cookies}, req.query, req.body )
|
||||
question(query, request)
|
||||
.then(answer => {
|
||||
console.log('[OK]', decodeURIComponent(req.originalUrl))
|
||||
|
@ -293,7 +293,10 @@ $ sudo docker run -d -p 3000:3000 netease-music-api
|
||||
|
||||
#### 1. 手机登录
|
||||
|
||||
**必选参数 :** `phone`: 手机号码 `password`: 密码
|
||||
**必选参数 :**
|
||||
`phone`: 手机号码
|
||||
|
||||
`password`: 密码
|
||||
|
||||
**接口地址 :** `/login/cellphone`
|
||||
|
||||
@ -303,22 +306,26 @@ $ sudo docker run -d -p 3000:3000 netease-music-api
|
||||
|
||||
#### 2. 邮箱登录
|
||||
|
||||
~~ 注意 : 此接口被网易和谐了 , 待修复 , 暂时使用手机登录 (2017.05.20)~~
|
||||
**必选参数 :**
|
||||
|
||||
> 更新 : 此接口已经可以正常使用(2018.07.03)
|
||||
`email`: 163 网易邮箱
|
||||
|
||||
**必选参数 :** `email`: 163 网易邮箱
|
||||
`password`: 密码
|
||||
|
||||
**接口地址 :** `/login`
|
||||
|
||||
**调用例子 :** `/login?email=xxx@163.com&password=yyy`
|
||||
|
||||
返回数据如下图 :
|
||||

|
||||
|
||||
完成登录后 , 会在浏览器保存一个 Cookies 用作登录凭证 , 大部分 API 都需要用到这个
|
||||
Cookies
|
||||
Cookies,非跨域情况请求会自动带上 Cookies,跨域情况参考`调用前须知`
|
||||
|
||||
v3.30.0后支持手动传入cookie,登录接口返回内容新增 `cookie` 字段,保存到本地后,get请求带上`?cookie=xxx` 或者 post请求body带上 `cookie` 即可,如:`/user/cloud?cookie=xxx` 或者
|
||||
```
|
||||
{
|
||||
...,
|
||||
cookie:"xxx"
|
||||
}
|
||||
```
|
||||
|
||||
#### 注意
|
||||
|
||||
@ -921,9 +928,7 @@ tags: 歌单标签
|
||||
说明 : 使用歌单详情接口后 , 能得到的音乐的 id, 但不能得到的音乐 url, 调用此接口
|
||||
, 传入的音乐 id( 可多个 , 用逗号隔开 ), 可以获取对应的音乐的 url( 不需要登录 )
|
||||
|
||||
> 注 : 部分用户反馈获取的 url 会 403,[hwaphon](https://github.com/hwaphon)找到的
|
||||
> 解决方案是当获取到音乐的 id 后,将
|
||||
> https://music.163.com/song/media/outer/url?id=id.mp3 以 src 赋予 Audio 即可播放
|
||||
> 注 : 部分用户反馈获取的 url 会 403,[hwaphon](https://github.com/hwaphon)找到的解决方案是当获取到音乐的 id 后,将 https://music.163.com/song/media/outer/url?id=id.mp3 以 src 赋予 Audio 即可播放
|
||||
|
||||
**必选参数 :** `id` : 音乐 id
|
||||
|
||||
|
@ -9,7 +9,7 @@ module.exports = async (query, request) => {
|
||||
password: crypto.createHash('md5').update(query.password).digest('hex'),
|
||||
rememberLogin: 'true'
|
||||
}
|
||||
const result = await request(
|
||||
let result = await request(
|
||||
'POST', `https://music.163.com/weapi/login`, data,
|
||||
{ crypto: 'weapi', ua: 'pc', cookie: query.cookie, proxy: query.proxy }
|
||||
)
|
||||
@ -23,5 +23,14 @@ module.exports = async (query, request) => {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (result.body.code === 200) {
|
||||
result = {
|
||||
status: 200,
|
||||
body: {
|
||||
...result.body,
|
||||
cookie: result.cookie.join(';')
|
||||
}
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
@ -2,7 +2,7 @@
|
||||
|
||||
const crypto = require('crypto')
|
||||
|
||||
module.exports = (query, request) => {
|
||||
module.exports = async (query, request) => {
|
||||
query.cookie.os = 'pc'
|
||||
const data = {
|
||||
phone: query.phone,
|
||||
@ -10,8 +10,19 @@ module.exports = (query, request) => {
|
||||
password: crypto.createHash('md5').update(query.password).digest('hex'),
|
||||
rememberLogin: 'true'
|
||||
}
|
||||
return request(
|
||||
let result = await request(
|
||||
'POST', `https://music.163.com/weapi/login/cellphone`, data,
|
||||
{crypto: 'weapi', ua: 'pc', cookie: query.cookie, proxy: query.proxy}
|
||||
)
|
||||
|
||||
if (result.body.code === 200) {
|
||||
result = {
|
||||
status: 200,
|
||||
body: {
|
||||
...result.body,
|
||||
cookie: result.cookie.join(';')
|
||||
}
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "NeteaseCloudMusicApi",
|
||||
"version": "3.29.1",
|
||||
"version": "3.30.0",
|
||||
"description": "网易云音乐 NodeJS 版 API",
|
||||
"scripts": {
|
||||
"start": "node app.js",
|
||||
|
@ -40,7 +40,6 @@ const createRequest = (method, url, data, options) => {
|
||||
if (url.includes('music.163.com'))
|
||||
headers['Referer'] = 'https://music.163.com'
|
||||
// headers['X-Real-IP'] = '118.88.88.88'
|
||||
|
||||
if (typeof options.cookie === 'object')
|
||||
headers['Cookie'] = Object.keys(options.cookie)
|
||||
.map(
|
||||
@ -52,6 +51,9 @@ const createRequest = (method, url, data, options) => {
|
||||
.join('; ')
|
||||
else if (options.cookie) headers['Cookie'] = options.cookie
|
||||
|
||||
if (!headers['Cookie']) {
|
||||
headers['Cookie'] = options.token || ''
|
||||
}
|
||||
if (options.crypto === 'weapi') {
|
||||
let csrfToken = (headers['Cookie'] || '').match(/_csrf=([^(;|$)]+)/)
|
||||
data.csrf_token = csrfToken ? csrfToken[1] : ''
|
||||
|
Loading…
x
Reference in New Issue
Block a user