mirror of
https://gitlab.com/Binaryify/neteasecloudmusicapi.git
synced 2025-07-05 17:28:55 +08:00
增加获取评论接口以及对应单元测试,增加更新日志
This commit is contained in:
parent
1eb6f3a59f
commit
77f848b74e
3
CHANGELOG.MD
Normal file
3
CHANGELOG.MD
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# 更新日志
|
||||||
|
## 2.1.0 | 2017.4.6
|
||||||
|
增加获取评论接口以及对应单元测试,增加更新日志
|
@ -29,6 +29,8 @@ $ node app.js
|
|||||||
|
|
||||||
[文档地址](https://binaryify.github.io/NeteaseCloudMusicApi)
|
[文档地址](https://binaryify.github.io/NeteaseCloudMusicApi)
|
||||||
|
|
||||||
|
## 更新日志
|
||||||
|
[看这里](https://github.com/Binaryify/NeteaseCloudMusicApi/blob/master/CHANGELOG.MD)
|
||||||
## 单元测试
|
## 单元测试
|
||||||
|
|
||||||
``` shell
|
``` shell
|
||||||
|
9
app.js
9
app.js
@ -5,19 +5,26 @@ const app = express()
|
|||||||
//手机登录
|
//手机登录
|
||||||
app.use('/login/cellphone', require('./router/loginCellphone'))
|
app.use('/login/cellphone', require('./router/loginCellphone'))
|
||||||
|
|
||||||
|
//邮箱登录
|
||||||
app.use('/login', require('./router/login'))
|
app.use('/login', require('./router/login'))
|
||||||
|
//获取评论
|
||||||
|
app.use('/comment', require('./router/comment'))
|
||||||
|
|
||||||
// 获取每日推荐歌曲
|
// 获取每日推荐歌曲
|
||||||
app.use('/recommend/songs', require('./router/recommendSongs'))
|
app.use('/recommend/songs', require('./router/recommendSongs'))
|
||||||
// 获取每日推荐歌单
|
// 获取每日推荐歌单
|
||||||
app.use('/recommend/resource', require('./router/recommendResource'))
|
app.use('/recommend/resource', require('./router/recommendResource'))
|
||||||
|
|
||||||
|
// 获取歌词
|
||||||
app.use('/lyric', require('./router/lyric'))
|
app.use('/lyric', require('./router/lyric'))
|
||||||
|
|
||||||
|
// 获取专辑
|
||||||
app.use('/album', require('./router/album'))
|
app.use('/album', require('./router/album'))
|
||||||
|
|
||||||
|
// 获取歌单
|
||||||
app.use('/user/playlist', require('./router/userPlaylist'))
|
app.use('/user/playlist', require('./router/userPlaylist'))
|
||||||
|
|
||||||
|
// 获取歌单内列表
|
||||||
app.use('/playlist/detail', require('./router/playlistDetail'))
|
app.use('/playlist/detail', require('./router/playlistDetail'))
|
||||||
|
|
||||||
app.use('/playlist/tracks', require('./router/playlistTracks'))
|
app.use('/playlist/tracks', require('./router/playlistTracks'))
|
||||||
|
132
docs/README.md
132
docs/README.md
@ -22,16 +22,31 @@ $ node app.js
|
|||||||
## 接口文档
|
## 接口文档
|
||||||
|
|
||||||
### 登录
|
### 登录
|
||||||
登录有两个接口
|
说明:登录有两个接口
|
||||||
1. 手机登录
|
#### 1. 手机登录
|
||||||
接口地址:
|
|
||||||
|
**必选参数:**
|
||||||
|
`phone`: 手机号码
|
||||||
|
`password`: 密码
|
||||||
|
|
||||||
|
**接口地址:**
|
||||||
`/login/cellphone`
|
`/login/cellphone`
|
||||||
调用例子:
|
|
||||||
|
**调用例子:**
|
||||||
`/login/cellphone?phone=xxx&password=yyy`
|
`/login/cellphone?phone=xxx&password=yyy`
|
||||||
2. 邮箱登录
|
|
||||||
接口地址:`/login`
|
#### 2. 邮箱登录
|
||||||
调用例子:
|
|
||||||
|
**必选参数:**
|
||||||
|
`email`: 163网易邮箱
|
||||||
|
`password`: 密码
|
||||||
|
|
||||||
|
**接口地址:**
|
||||||
|
`/login`
|
||||||
|
|
||||||
|
**调用例子:**
|
||||||
`/login?email=xxx@163.com&password=yyy`
|
`/login?email=xxx@163.com&password=yyy`
|
||||||
|
|
||||||
返回数据如下图:
|
返回数据如下图:
|
||||||

|

|
||||||
|
|
||||||
@ -43,68 +58,121 @@ $ node app.js
|
|||||||
|
|
||||||
### 获取用户歌单
|
### 获取用户歌单
|
||||||
说明:登陆后调用此接口,传入用户 id, 可以获取用户歌单
|
说明:登陆后调用此接口,传入用户 id, 可以获取用户歌单
|
||||||
接口地址:
|
|
||||||
|
**必选参数:**
|
||||||
|
`uid` : 用户 id
|
||||||
|
|
||||||
|
**接口地址:**
|
||||||
`/user/playlist`
|
`/user/playlist`
|
||||||
调用例子:
|
|
||||||
|
**调用例子:**
|
||||||
`/user/playlist?uid=32953014`
|
`/user/playlist?uid=32953014`
|
||||||
|
|
||||||
返回数据如下图:
|
返回数据如下图:
|
||||||

|

|
||||||
|
|
||||||
### 获取歌单详情
|
### 获取歌单详情
|
||||||
说明:歌单能看到歌单名字,但看不到具体歌单内容,调用此接口,传入歌单 id,可以获取对应歌单内的所有的音乐
|
说明:歌单能看到歌单名字,但看不到具体歌单内容,调用此接口,传入歌单 id,可以获取对应歌单内的所有的音乐
|
||||||
接口地址:
|
|
||||||
|
**必选参数:**
|
||||||
|
`id` : 歌单 id
|
||||||
|
|
||||||
|
**接口地址:**
|
||||||
`playlist/detail`
|
`playlist/detail`
|
||||||
调用例子:
|
|
||||||
|
**调用例子:**
|
||||||
`/playlist/detail?id=24381616`
|
`/playlist/detail?id=24381616`
|
||||||
|
|
||||||
返回数据如下图:
|
返回数据如下图:
|
||||||

|

|
||||||
|
|
||||||
### 获取音乐 url
|
### 获取音乐 url
|
||||||
说明:使用歌单详情接口后,能得到的音乐的 id, 但不能得到的音乐 url, 调用此接口,传入的音乐 id,可以获取对应的音乐的 url(不需要登录)
|
说明:使用歌单详情接口后,能得到的音乐的 id, 但不能得到的音乐 url, 调用此接口,传入的音乐 id,可以获取对应的音乐的 url(不需要登录)
|
||||||
接口地址:
|
|
||||||
|
**必选参数:**
|
||||||
|
`id` : 音乐 id
|
||||||
|
|
||||||
|
**接口地址:**
|
||||||
`playlist/detail`
|
`playlist/detail`
|
||||||
调用例子:
|
|
||||||
|
**调用例子:**
|
||||||
`/playlist/detail?id=24381616`
|
`/playlist/detail?id=24381616`
|
||||||
|
|
||||||
返回数据如下图:
|
返回数据如下图:
|
||||||

|

|
||||||
|
|
||||||
### 搜索音乐
|
### 搜索音乐
|
||||||
说明:调用此接口,传入搜索关键词可以搜索该音乐,关键词可以多个,以空格隔开,如"周杰伦 搁浅"(不需要登录)
|
说明:调用此接口,传入搜索关键词可以搜索该音乐,关键词可以多个,以空格隔开,如"周杰伦 搁浅"(不需要登录)
|
||||||
必选参数:
|
|
||||||
keywords : 关键词
|
**必选参数:**
|
||||||
可选参数:
|
`keywords` : 关键词
|
||||||
limit: 返回数量,默认为30
|
|
||||||
type: 搜索类型;默认为1,取值意义:
|
**可选参数:**
|
||||||
|
`limit` : 返回数量,默认为30
|
||||||
|
`type`: 搜索类型;默认为1,取值意义:
|
||||||
1: 单曲
|
1: 单曲
|
||||||
10: 专辑
|
10: 专辑
|
||||||
100: 歌手
|
100: 歌手
|
||||||
1000: 歌单
|
1000: 歌单
|
||||||
1002: 用户
|
1002: 用户
|
||||||
|
|
||||||
offset: 偏移数量,用于分页
|
`offset` : 偏移数量,用于分页
|
||||||
|
|
||||||
接口地址:
|
**接口地址:**
|
||||||
`/search`
|
`/search`
|
||||||
调用例子:
|
|
||||||
|
**调用例子:**
|
||||||
`/search?keywords=海阔天空`
|
`/search?keywords=海阔天空`
|
||||||
|
|
||||||
返回数据如下图:
|
返回数据如下图:
|
||||||

|

|
||||||
|
|
||||||
### 获取歌词
|
### 获取歌词
|
||||||
说明:调用此接口,传入音乐 id 可获得对应音乐的歌词(不需要登录)
|
说明:调用此接口,传入音乐 id 可获得对应音乐的歌词(不需要登录)
|
||||||
接口地址:
|
|
||||||
|
**必选参数:**
|
||||||
|
`id`: 音乐 id
|
||||||
|
|
||||||
|
**接口地址:**
|
||||||
`/lyric`
|
`/lyric`
|
||||||
调用例子:
|
|
||||||
|
**调用例子:**
|
||||||
`/lyric?id=347230`
|
`/lyric?id=347230`
|
||||||
|
|
||||||
返回数据如下图:
|
返回数据如下图:
|
||||||

|

|
||||||
|
|
||||||
|
### 获取评论
|
||||||
|
说明:调用此接口,传入歌音乐 id和 limit 参数, 可获得该音乐的所有评论(不需要登录)
|
||||||
|
|
||||||
|
**必选参数:**
|
||||||
|
`id`: 音乐 id
|
||||||
|
|
||||||
|
**可选参数:**
|
||||||
|
`limit`: 取出评论数量,默认为20
|
||||||
|
|
||||||
|
**接口地址:**
|
||||||
|
`/comment`
|
||||||
|
|
||||||
|
**调用例子:**
|
||||||
|
`/comment?id=186016&limit=1`
|
||||||
|
|
||||||
|
返回数据如下图:
|
||||||
|

|
||||||
|
|
||||||
### 获取歌手专辑列表
|
### 获取歌手专辑列表
|
||||||
说明:调用此接口,传入歌手 id,可获得歌手专辑列表
|
说明:调用此接口,传入歌手 id,可获得歌手专辑列表
|
||||||
接口地址:
|
|
||||||
|
**必选参数:**
|
||||||
|
`id`: 歌手 id
|
||||||
|
|
||||||
|
**接口地址:**
|
||||||
`/album`
|
`/album`
|
||||||
调用例子:
|
|
||||||
|
**调用例子:**
|
||||||
`album?id=32311`
|
`album?id=32311`
|
||||||
|
|
||||||
|
返回数据如下图:
|
||||||

|

|
||||||
|
|
||||||
|
|
||||||
@ -112,19 +180,25 @@ type: 搜索类型;默认为1,取值意义:
|
|||||||
|
|
||||||
### 获取每日推荐歌单
|
### 获取每日推荐歌单
|
||||||
说明:调用此接口,可获得每日推荐歌单(需要登录)
|
说明:调用此接口,可获得每日推荐歌单(需要登录)
|
||||||
接口地址:
|
|
||||||
|
**接口地址:**
|
||||||
`/recommend/resource`
|
`/recommend/resource`
|
||||||
调用例子:
|
|
||||||
|
**调用例子:**
|
||||||
`/recommend/resource`
|
`/recommend/resource`
|
||||||
|
|
||||||
返回数据如下图:
|
返回数据如下图:
|
||||||

|

|
||||||
|
|
||||||
### 获取每日推荐歌曲
|
### 获取每日推荐歌曲
|
||||||
说明:调用此接口,可获得每日推荐歌曲(需要登录)
|
说明:调用此接口,可获得每日推荐歌曲(需要登录)
|
||||||
接口地址:
|
|
||||||
|
**接口地址:**
|
||||||
`/recommend/songs`
|
`/recommend/songs`
|
||||||
调用例子:
|
|
||||||
|
**调用例子:**
|
||||||
`/recommend/songs`
|
`/recommend/songs`
|
||||||
|
|
||||||
返回数据如下图:
|
返回数据如下图:
|
||||||

|

|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "NeteaseCloudMusicApi",
|
"name": "NeteaseCloudMusicApi",
|
||||||
"version": "2.0.3",
|
"version": "2.1.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node app.js",
|
"start": "node app.js",
|
||||||
@ -8,7 +8,7 @@
|
|||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"big-integer": "^1.6.17",
|
"big-integer": "^1.6.17",
|
||||||
"express": "^4.15.2"
|
"express": "^4.15.2"
|
||||||
|
25
router/comment.js
Normal file
25
router/comment.js
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
const express = require("express")
|
||||||
|
const router = express()
|
||||||
|
const { createWebAPIRequest } = require("../util/util")
|
||||||
|
|
||||||
|
router.get("/", (req, res) => {
|
||||||
|
const rid=req.query.id
|
||||||
|
const cookie = req.get('Cookie') ? req.get('Cookie') : ''
|
||||||
|
const data = {
|
||||||
|
"offset": 0,
|
||||||
|
"rid": rid,
|
||||||
|
"limit": req.query.limit || 20,
|
||||||
|
"csrf_token": ""
|
||||||
|
}
|
||||||
|
createWebAPIRequest(
|
||||||
|
'music.163.com',
|
||||||
|
`/weapi/v1/resource/comments/R_SO_4_${rid}/?csrf_token=`,
|
||||||
|
'POST',
|
||||||
|
data,
|
||||||
|
cookie,
|
||||||
|
music_req => res.send(music_req),
|
||||||
|
err => res.status(502).send('fetch error')
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
module.exports = router
|
31
test/comment.test.js
Normal file
31
test/comment.test.js
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
const assert = require('assert')
|
||||||
|
const crypto = require('crypto')
|
||||||
|
const { createWebAPIRequest } = require("../util/util")
|
||||||
|
|
||||||
|
describe('测试获取评论是否正常', () => {
|
||||||
|
it('数据的 code 应该为200', done => {
|
||||||
|
const rid = 32311
|
||||||
|
const cookie = ''
|
||||||
|
const data = {
|
||||||
|
"offset": 0,
|
||||||
|
"rid": rid,
|
||||||
|
"limit": 20,
|
||||||
|
"csrf_token": ""
|
||||||
|
}
|
||||||
|
createWebAPIRequest(
|
||||||
|
'music.163.com',
|
||||||
|
`/weapi/v1/resource/comments/R_SO_4_${rid}/?csrf_token=`,
|
||||||
|
'POST',
|
||||||
|
data,
|
||||||
|
cookie,
|
||||||
|
music_req => {
|
||||||
|
console.log({
|
||||||
|
code:JSON.parse(music_req).code
|
||||||
|
})
|
||||||
|
assert(JSON.parse(music_req).code === 200)
|
||||||
|
done()
|
||||||
|
},
|
||||||
|
err => done(err)
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
Loading…
x
Reference in New Issue
Block a user