update: 文档和示例更新

This commit is contained in:
binaryify 2024-03-12 14:29:31 +08:00
parent 571c35da55
commit dfcdc04fbb
12 changed files with 506 additions and 584 deletions

View File

@ -1,4 +1,7 @@
# 更新日志 # 更新日志
### 4.15.6 | 2024.03.12
- 文档和示例更新
### 4.15.5 | 2024.02.28 ### 4.15.5 | 2024.02.28
- 文档更新 - 文档更新

View File

@ -10,7 +10,6 @@
<a href="https://codeclimate.com/github/Binaryify/NeteaseCloudMusicApi"><img src="https://codeclimate.com/github/Binaryify/NeteaseCloudMusicApi/badges/gpa.svg" /></a> <a href="https://codeclimate.com/github/Binaryify/NeteaseCloudMusicApi"><img src="https://codeclimate.com/github/Binaryify/NeteaseCloudMusicApi/badges/gpa.svg" /></a>
</p> </p>
## 灵感来自 ## 灵感来自
[disoul/electron-cloud-music](https://github.com/disoul/electron-cloud-music) [disoul/electron-cloud-music](https://github.com/disoul/electron-cloud-music)
@ -21,7 +20,6 @@
[greats3an/pyncm](https://github.com/greats3an/pyncm) [greats3an/pyncm](https://github.com/greats3an/pyncm)
## 环境要求 ## 环境要求
需要 NodeJS 14+ 环境 需要 NodeJS 14+ 环境
@ -43,6 +41,7 @@ $ npm install
``` ```
## 运行 ## 运行
调用前务必阅读文档的`调用前须知` 调用前务必阅读文档的`调用前须知`
```shell ```shell
@ -62,12 +61,14 @@ $ set PORT=4000 && node app.js
``` ```
## npx 方式运行 ## npx 方式运行
可在终端直接执行 可在终端直接执行
```bash ```bash
npx NeteaseCloudMusicApi@latest npx NeteaseCloudMusicApi@latest
``` ```
使用此命令,可直接启动服务,无需下载或者 clone 项目
使用此命令,可直接启动服务,无需下载或者 clone 项目
## Vercel 部署 ## Vercel 部署
@ -83,24 +84,29 @@ v4.0.8 加入了 Vercel 配置文件,可以直接在 Vercel 下部署了,不需
6. `PROJECT NAME`自己填,`FRAMEWORK PRESET` 选 `Other` 然后直接点 `Deploy` 接着等部署完成即可 6. `PROJECT NAME`自己填,`FRAMEWORK PRESET` 选 `Other` 然后直接点 `Deploy` 接着等部署完成即可
## 腾讯云 serverless 部署 ## 腾讯云 serverless 部署
因 `Vercel` 在国内访问太慢,在此提供腾讯云 serverless 部署方法(注意:腾讯云 serverless 并不是免费的,前三个月有免费额度,之后收费) 因 `Vercel` 在国内访问太慢,在此提供腾讯云 serverless 部署方法(注意:腾讯云 serverless 并不是免费的,前三个月有免费额度,之后收费)
### 操作方法 ### 操作方法
1. fork 此项目 1. fork 此项目
2. 在腾讯云serverless应用管理页面( https://console.cloud.tencent.com/sls ),点击`新建应用` 2. 在腾讯云 serverless 应用管理页面( https://console.cloud.tencent.com/sls ),点击`新建应用`
3. 顶部`创建方式`选择 `Web 应用` 3. 顶部`创建方式`选择 `Web 应用`
4. 选择 `Express框架`,点击底部`下一步按钮` 4. 选择 `Express框架`,点击底部`下一步按钮`
5. 输入`应用名`,上传方式选择`代码仓库`,进行GitHub授权(如已授权可跳过这一步),代码仓库选择刚刚fork的项目 5. 输入`应用名`,上传方式选择`代码仓库`,进行 GitHub 授权(如已授权可跳过这一步),代码仓库选择刚刚 fork 的项目
6. 启动文件填入: 6. 启动文件填入:
``` ```
#!/bin/bash #!/bin/bash
export PORT=9000 export PORT=9000
/var/lang/node16/bin/node app.js /var/lang/node16/bin/node app.js
``` ```
7. 点击`完成`,等待部署完成,点击`资源列表`的 `API网关` 里的 `URL`,正常情况会打开文档地址,点击文档`例子`可查看接口调用效果 7. 点击`完成`,等待部署完成,点击`资源列表`的 `API网关` 里的 `URL`,正常情况会打开文档地址,点击文档`例子`可查看接口调用效果
## 可以在Node.js调用 ## 可以在 Node.js 调用
v3.31.0后支持Node.js调用,导入的方法为`module`内的文件名,返回内容包含`status`和`body`,`status`为状态码,`body`为请求返回内容,参考`module_example` 文件夹下的 `test.js` v3.31.0 后支持 Node.js 调用,导入的方法为`module`内的文件名,返回内容包含`status`和`body`,`status`为状态码,`body`为请求返回内容,参考`module_example` 文件夹下的 `test.js`
```js ```js
const { login_cellphone, user_cloud } = require('NeteaseCloudMusicApi') const { login_cellphone, user_cloud } = require('NeteaseCloudMusicApi')
@ -108,14 +114,13 @@ async function main() {
try { try {
const result = await login_cellphone({ const result = await login_cellphone({
phone: '手机号', phone: '手机号',
password: '密码' password: '密码',
}) })
console.log(result) console.log(result)
const result2 = await user_cloud({ const result2 = await user_cloud({
cookie: result.body.cookie // 凭证 cookie: result.body.cookie, // 凭证
}) })
console.log(result2.body) console.log(result2.body)
} catch (error) { } catch (error) {
console.log(error) console.log(error)
} }
@ -128,20 +133,15 @@ main()
```ts ```ts
// test.ts // test.ts
import { banner } from 'NeteaseCloudMusicApi' import { banner } from 'NeteaseCloudMusicApi'
banner({ type:0 }).then(res=>{ banner({ type: 0 }).then((res) => {
console.log(res) console.log(res)
}) })
``` ```
## 使用文档 ## 使用文档
[文档地址](https://docs-neteasecloudmusicapi.vercel.app) [文档地址](https://docs-neteasecloudmusicapi.vercel.app)
![文档](https://raw.githubusercontent.com/Binaryify/NeteaseCloudMusicApi/master/public/static/docs.png)
## 功能特性 ## 功能特性
1. 登录 1. 登录
@ -259,10 +259,10 @@ banner({ type:0 }).then(res=>{
113. 云盘数据详情 113. 云盘数据详情
114. 私信内容 114. 私信内容
115. 我的数字专辑 115. 我的数字专辑
116. batch批量请求接口 116. batch 批量请求接口
117. 获取视频标签列表 117. 获取视频标签列表
118. 全部mv 118. 全部 mv
119. 网易出品mv 119. 网易出品 mv
120. 收藏/取消收藏专辑 120. 收藏/取消收藏专辑
121. 专辑动态信息 121. 专辑动态信息
122. 热搜列表(详细) 122. 热搜列表(详细)
@ -274,7 +274,7 @@ banner({ type:0 }).then(res=>{
128. 更新歌单标签 128. 更新歌单标签
129. 默认搜索关键词 129. 默认搜索关键词
130. 删除歌单 130. 删除歌单
131. 电台banner 131. 电台 banner
132. 用户电台 132. 用户电台
133. 热门电台 133. 热门电台
134. 电台 - 节目详情 134. 电台 - 节目详情
@ -282,12 +282,12 @@ banner({ type:0 }).then(res=>{
136. 电台 - 新晋电台榜/热门电台榜 136. 电台 - 新晋电台榜/热门电台榜
137. 类别热门电台 137. 类别热门电台
138. 云村热评 138. 云村热评
139. 电台24小时节目榜 139. 电台 24 小时节目榜
140. 电台24小时主播榜 140. 电台 24 小时主播榜
141. 电台最热主播榜 141. 电台最热主播榜
142. 电台主播新人榜 142. 电台主播新人榜
143. 电台付费精品榜 143. 电台付费精品榜
144. 歌手热门50首歌曲 144. 歌手热门 50 首歌曲
145. 购买数字专辑 145. 购买数字专辑
146. 获取 mv 点赞转发评论数数据 146. 获取 mv 点赞转发评论数数据
147. 获取视频点赞转发评论数数据 147. 获取视频点赞转发评论数数据
@ -326,7 +326,7 @@ banner({ type:0 }).then(res=>{
180. 云贝签到信息 180. 云贝签到信息
181. 云贝签到 181. 云贝签到
182. 云贝所有任务 182. 云贝所有任务
183. 云贝todo任务 183. 云贝 todo 任务
184. 云贝今日签到信息 184. 云贝今日签到信息
185. 云贝完成任务 185. 云贝完成任务
186. 云贝收入 186. 云贝收入
@ -339,7 +339,7 @@ banner({ type:0 }).then(res=>{
193. 评论抱一抱列表 193. 评论抱一抱列表
194. 收藏的专栏 194. 收藏的专栏
195. 关注歌手新歌 195. 关注歌手新歌
196. 关注歌手新MV 196. 关注歌手新 MV
197. 歌手详情 197. 歌手详情
198. 云盘上传 198. 云盘上传
199. 二维码登录 199. 二维码登录
@ -353,12 +353,12 @@ banner({ type:0 }).then(res=>{
207. 云贝推歌 207. 云贝推歌
208. 云贝推歌历史记录 208. 云贝推歌历史记录
209. 已购单曲 209. 已购单曲
210. 获取mlog播放地址 210. 获取 mlog 播放地址
211. 将mlog id转为视频id 211. 将 mlog id 转为视频 id
212. vip成长值 212. vip 成长值
213. vip成长值获取记录 213. vip 成长值获取记录
214. vip任务 214. vip 任务
215. 领取vip成长值 215. 领取 vip 成长值
216. 歌手粉丝 216. 歌手粉丝
217. 数字专辑详情 217. 数字专辑详情
218. 数字专辑销量 218. 数字专辑销量
@ -403,12 +403,12 @@ banner({ type:0 }).then(res=>{
257. 验证接口-二维码生成 257. 验证接口-二维码生成
258. 验证接口-二维码检测 258. 验证接口-二维码检测
259. 听歌识曲 259. 听歌识曲
260. 根据nickname获取userid接口 260. 根据 nickname 获取 userid 接口
261. 播客声音列表 261. 播客声音列表
262. 专辑简要百科信息 262. 专辑简要百科信息
263. 歌曲简要百科信息 263. 歌曲简要百科信息
264. 歌手简要百科信息 264. 歌手简要百科信息
265. mv简要百科信息 265. mv 简要百科信息
266. 搜索歌手 266. 搜索歌手
267. 用户贡献内容 267. 用户贡献内容
268. 用户贡献条目、积分、云贝数量 268. 用户贡献条目、积分、云贝数量
@ -421,28 +421,24 @@ banner({ type:0 }).then(res=>{
275. 歌曲红心数量 275. 歌曲红心数量
276. 私人 FM 模式选择 276. 私人 FM 模式选择
## 单元测试 ## 单元测试
```shell ```shell
$ npm test $ npm test
``` ```
## SDK ## SDK
| 语言 | 作者 | 地址 | 类型 | | 语言 | 作者 | 地址 | 类型 |
| :--: | :-----------------------------------------: | :----------------------------------------------------------: | :----: | | :----: | :-----------------------------------------: | :--------------------------------------------------------------------------------------------------------: | :----: |
| Java | [JackuXL](https://github.com/JackuXL) | [https://github.com/JackuXL/NeteaseCloudMusicApi-SDK](https://github.com/JackuXL/NeteaseCloudMusicApi-SDK) | 第三方 | | Java | [JackuXL](https://github.com/JackuXL) | [https://github.com/JackuXL/NeteaseCloudMusicApi-SDK](https://github.com/JackuXL/NeteaseCloudMusicApi-SDK) | 第三方 |
| Java | [1015770492](https://github.com/1015770492) | https://github.com/1015770492/yumbo-music-utils | 第三方 | | Java | [1015770492](https://github.com/1015770492) | https://github.com/1015770492/yumbo-music-utils | 第三方 |
| Python | [盧瞳](https://github.com/2061360308) | [NeteaseCloudMusic_PythonSDK](https://github.com/2061360308/NeteaseCloudMusic_PythonSDK) | 第三方 | | Python | [盧瞳](https://github.com/2061360308) | [NeteaseCloudMusic_PythonSDK](https://github.com/2061360308/NeteaseCloudMusic_PythonSDK) | 第三方 |
## 贡献者 ## 贡献者
![](https://opencollective.com/NeteaseCloudMusicApi/contributors.svg?width=890) ![](https://opencollective.com/NeteaseCloudMusicApi/contributors.svg?width=890)
## License ## License
[The MIT License (MIT)](https://gitlab.com/Binaryify/NeteaseCloudMusicApi/blob/main/LICENSE) [The MIT License (MIT)](https://gitlab.com/Binaryify/NeteaseCloudMusicApi/blob/main/LICENSE)

View File

@ -1,6 +1,6 @@
{ {
"name": "NeteaseCloudMusicApi", "name": "NeteaseCloudMusicApi",
"version": "4.15.5", "version": "4.15.6",
"description": "网易云音乐 NodeJS 版 API", "description": "网易云音乐 NodeJS 版 API",
"scripts": { "scripts": {
"start": "node app.js", "start": "node app.js",

View File

@ -1,28 +1,25 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="zh"> <html lang="zh">
<head>
<head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>更新头像</title> <title>更新头像</title>
</head> </head>
<body> <body>
<div>
<a href="/qrlogin-nocookie.html">
如果没登录,请先登录
</a>
</div>
<input id="file" type="file" /> <input id="file" type="file" />
<img id="avatar" style="height: 200px; width: 200px; border-radius: 50%" /> <img id="avatar" style="height: 200px; width: 200px; border-radius: 50%" />
<script src="https://cdn.jsdelivr.net/npm/axios@0.26.1/dist/axios.min.js <script src="https://cdn.jsdelivr.net/npm/axios@0.26.1/dist/axios.min.js
"></script> "></script>
<script> <script>
const phone = ''
const password = ''
let cookieToken = ''
if (!phone || !password) {
const msg = '请设置你的手机号码和密码'
alert(msg)
throw new Error(msg)
}
main() main()
login()
async function main() { async function main() {
document.querySelector('input[type="file"]').addEventListener( document.querySelector('input[type="file"]').addEventListener(
'change', 'change',
@ -38,21 +35,14 @@
}) })
document.querySelector('#avatar').src = res.data.profile.avatarUrl document.querySelector('#avatar').src = res.data.profile.avatarUrl
} }
async function login() {
const res = await axios({
url: `/login/cellphone?phone=${phone}&password=${password}`,
withCredentials: true, //跨域的话必须设置
})
cookieToken = res.data.cookie
}
async function upload(file) { async function upload(file) {
var formData = new FormData() var formData = new FormData()
formData.append('imgFile', file) formData.append('imgFile', file)
const imgSize = await getImgSize(file) const imgSize = await getImgSize(file)
const res = await axios({ const res = await axios({
method: 'post', method: 'post',
url: `/avatar/upload?cookie=${cookieToken}&imgSize=${ url: `/avatar/upload?cookie=${localStorage.getItem('cookie')}&imgSize=${imgSize.width
imgSize.width
}&imgX=0&imgY=0&timestamp=${Date.now()}`, }&imgX=0&imgY=0&timestamp=${Date.now()}`,
headers: { headers: {
'Content-Type': 'multipart/form-data', 'Content-Type': 'multipart/form-data',
@ -78,5 +68,6 @@
}) })
} }
</script> </script>
</body> </body>
</html> </html>

View File

@ -8,29 +8,48 @@
</head> </head>
<body> <body>
<div>
<a href="/qrlogin-nocookie.html">
如果没登录,请先登录
</a>
</div>
<input id="file" type="file" multiple /> <input id="file" type="file" multiple />
<div id="app">
<ul>
<li v-for="(item,index) in songs" :key="index">
{{item.songName}}
</li>
</ul>
</div>
<script src="https://cdn.jsdelivr.net/npm/axios@0.26.1/dist/axios.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/axios@0.26.1/dist/axios.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script> <script>
const phone = '' // 这里填手机号 const app = Vue.createApp({
const password = '' // 这里填密码 data() {
return {
songs: []
}
},
created() {
this.getData()
},
methods: {
getData() {
console.log('getdata');
const _this = this
axios({
url: `/user/cloud?time=${Date.now()}&cookie=${localStorage.getItem('cookie')}`,
}).then(res => {
console.log(res.data)
_this.songs = res.data.data
})
}
}
}).mount('#app')
const fileUpdateTime = {} const fileUpdateTime = {}
let fileLength = 0 let fileLength = 0
let cookieToken = ''
if (!phone || !password) {
const msg = '请设置你的手机号码和密码'
alert(msg)
throw new Error(msg)
}
login()
main()
async function login() {
const res = await axios({
url: `/login/cellphone?phone=${phone}&password=${encodeURIComponent(password)}`,
withCredentials: true, //跨域的话必须设置
})
cookieToken = res.data.cookie
}
function main() { function main() {
document document
.querySelector('input[type="file"]') .querySelector('input[type="file"]')
@ -44,13 +63,14 @@
} }
}) })
} }
main()
function upload(file, currentIndx) { function upload(file, currentIndx) {
var formData = new FormData() var formData = new FormData()
formData.append('songFile', file) formData.append('songFile', file)
axios({ axios({
method: 'post', method: 'post',
url: `/cloud?time=${Date.now()}&cookie=${cookieToken}`, url: `/cloud?time=${Date.now()}&cookie=${localStorage.getItem('cookie')}`,
headers: { headers: {
'Content-Type': 'multipart/form-data', 'Content-Type': 'multipart/form-data',
}, },
@ -58,6 +78,7 @@
}).then(res => { }).then(res => {
console.log(`${file.name} 上传成功`) console.log(`${file.name} 上传成功`)
if (currentIndx >= fileLength) { console.log('上传完毕') } if (currentIndx >= fileLength) { console.log('上传完毕') }
app.getData()
}).catch(async err => { }).catch(async err => {
console.log(err) console.log(err)
console.log(fileUpdateTime) console.log(fileUpdateTime)

View File

@ -8,32 +8,18 @@
</head> </head>
<body> <body>
<div>
<a href="/qrlogin-nocookie.html">
如果没登录,请先登录
</a>
</div>
<script src="https://cdn.jsdelivr.net/npm/axios@0.26.1/dist/axios.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/axios@0.26.1/dist/axios.min.js"></script>
<script> <script>
const phone = '' // 这里填手机号
const password = '' // 这里填密码
const fileUpdateTime = {}
let cookieToken = ''
if (!phone || !password) {
const msg = '请设置你的手机号码和密码'
alert(msg)
throw new Error(msg)
}
async function login() {
const res = await axios({
url: `/login/cellphone?phone=${phone}&password=${encodeURIComponent(
password,
)}`,
})
cookieToken = res.data.cookie
}
async function main() { async function main() {
await login()
const res = await axios({ const res = await axios({
url: `/homepage/block/page`, url: `/homepage/block/page`,
data: { data: {
cookie: cookieToken, cookie: localStorage.getItem('cookie'),
}, },
method: 'post', method: 'post',
}) })
@ -44,7 +30,7 @@
const res2 = await axios({ const res2 = await axios({
url: `/homepage/block/page?time=${Date.now()}`, url: `/homepage/block/page?time=${Date.now()}`,
data: { data: {
cookie: cookieToken, cookie: localStorage.getItem('cookie'),
cursor: cursor, cursor: cursor,
}, },
method: 'post', method: 'post',

View File

@ -13,12 +13,14 @@
</head> </head>
<body class="mdui-container"> <body class="mdui-container">
<div>
<a href="/qrlogin-nocookie.html">
如果没登录,请先登录
</a>
</div>
<h1>一起听 - 主机模式</h1> <h1>一起听 - 主机模式</h1>
<div>消息: {{message}}</div> <div>消息: {{message}}</div>
<audio <audio id="player" autoplay controls>
id="player"
autoplay
controls>
</audio> </audio>
<br /> <br />
<br /> <br />
@ -59,8 +61,7 @@
<br /> <br />
<div>歌单内容: </div> <div>歌单内容: </div>
<ul class="mdui-list"> <ul class="mdui-list">
<li @click="gotoTrack(track.id)" v-for="track in playlistInfo.playlistTracks" <li @click="gotoTrack(track.id)" v-for="track in playlistInfo.playlistTracks" class="mdui-list-item mdui-ripple">
class="mdui-list-item mdui-ripple">
<div class="mdui-list-item-avatar"> <div class="mdui-list-item-avatar">
<img :src="track.al.picUrl" /> <img :src="track.al.picUrl" />
</div> </div>
@ -98,6 +99,9 @@
const res = await axios({ const res = await axios({
url: `/login/status`, url: `/login/status`,
method: 'get', method: 'get',
data: {
cookie: localStorage.getItem('cookie'),
},
}) })
if (res.data.data.code != 200) { if (res.data.data.code != 200) {
alert('请先使用登录 API 登录到网易云音乐') alert('请先使用登录 API 登录到网易云音乐')
@ -112,6 +116,9 @@
const res = await axios({ const res = await axios({
url: 'listentogether/room/create', url: 'listentogether/room/create',
method: 'get', method: 'get',
data: {
cookie: localStorage.getItem('cookie'),
},
}) })
console.log(res) console.log(res)
if (res.data.code != 200) { if (res.data.code != 200) {
@ -119,19 +126,23 @@
} else { } else {
this.message = '创建房间成功: ' + res.data.data.roomInfo.roomId this.message = '创建房间成功: ' + res.data.data.roomInfo.roomId
this.roomInfo.roomId = res.data.data.roomInfo.roomId this.roomInfo.roomId = res.data.data.roomInfo.roomId
res = await axios({ const res2 = await axios({
url: 'listentogether/room/check', url: 'listentogether/room/check',
method: 'post', method: 'post',
data: { data: {
roomId: this.roomInfo.roomId, roomId: this.roomInfo.roomId,
cookie: localStorage.getItem('cookie'),
}, },
}) })
console.log(res) console.log(res2)
} }
}, },
refreshRoom: async function () { refreshRoom: async function () {
const res = await axios({ const res = await axios({
url: '/listentogether/status', url: '/listentogether/status',
data: {
cookie: localStorage.getItem('cookie'),
},
}) })
console.log(res) console.log(res)
if (res.data.code != 200 || !res.data.data.inRoom) { if (res.data.code != 200 || !res.data.data.inRoom) {
@ -146,6 +157,8 @@
method: 'post', method: 'post',
data: { data: {
roomId: this.roomInfo.roomId, roomId: this.roomInfo.roomId,
cookie: localStorage.getItem('cookie'),
}, },
}) })
console.log(res) console.log(res)
@ -162,6 +175,7 @@
method: 'post', method: 'post',
data: { data: {
id: this.playlistInfo.playlistId, id: this.playlistInfo.playlistId,
cookie: localStorage.getItem('cookie'),
}, },
}) })
console.log(res) console.log(res)
@ -174,6 +188,7 @@
method: 'post', method: 'post',
data: { data: {
ids: this.playlistInfo.playlistTrackIds, ids: this.playlistInfo.playlistTrackIds,
cookie: localStorage.getItem('cookie'),
}, },
}) })
console.log(resa) console.log(resa)
@ -190,6 +205,7 @@
playMode: 'ORDER_LOOP', playMode: 'ORDER_LOOP',
displayList: this.playlistInfo.playlistTrackIds, displayList: this.playlistInfo.playlistTrackIds,
randomList: this.playlistInfo.playlistTrackIds, randomList: this.playlistInfo.playlistTrackIds,
cookie: localStorage.getItem('cookie'),
}, },
}) })
console.log(resb) console.log(resb)
@ -232,6 +248,7 @@
targetSongId: this.playingInfo.trackId, targetSongId: this.playingInfo.trackId,
clientSeq: this.clientSeq++, clientSeq: this.clientSeq++,
playStatus: this.playingInfo.status, playStatus: this.playingInfo.status,
cookie: localStorage.getItem('cookie'),
}, },
}) })
console.log(res) console.log(res)

View File

@ -1,28 +1,23 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="zh"> <html lang="zh">
<head>
<head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>歌单封面上传</title> <title>歌单封面上传</title>
</head> </head>
<body> <body>
<div>
<a href="/qrlogin-nocookie.html">
如果没登录,请先登录
</a>
</div>
<input id="file" type="file" name="filename" /> <input id="file" type="file" name="filename" />
<img <img id="playlist_cover" style="height: 200px; width: 200px; border-radius: 50%" />
id="playlist_cover"
style="height: 200px; width: 200px; border-radius: 50%"
/>
<script src="https://cdn.jsdelivr.net/npm/axios@0.26.1/dist/axios.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/axios@0.26.1/dist/axios.min.js"></script>
<script> <script>
const phone = ''
const password = ''
const playlist_id = '' const playlist_id = ''
let cookieToken = ''
if (!phone || !password) {
const msg = '请设置你的手机号码和密码'
alert(msg)
throw new Error(msg)
}
if (!playlist_id) { if (!playlist_id) {
const msg = '请设置你的歌单id' const msg = '请设置你的歌单id'
alert(msg) alert(msg)
@ -30,7 +25,6 @@
} }
main() main()
login()
async function main() { async function main() {
document.querySelector('input[type="file"]').addEventListener( document.querySelector('input[type="file"]').addEventListener(
'change', 'change',
@ -45,21 +39,14 @@
}) })
document.querySelector('#playlist_cover').src = res.data.playlist.coverImgUrl document.querySelector('#playlist_cover').src = res.data.playlist.coverImgUrl
} }
async function login() {
const res = await axios({
url: `/login/cellphone?phone=${phone}&password=${password}`,
withCredentials: true, //跨域的话必须设置
})
cookieToken = res.data.cookie
}
async function upload(file) { async function upload(file) {
var formData = new FormData() var formData = new FormData()
formData.append('imgFile', file) formData.append('imgFile', file)
const imgSize = await getImgSize(file) const imgSize = await getImgSize(file)
const res = await axios({ const res = await axios({
method: 'post', method: 'post',
url: `/playlist/cover/update?id=${playlist_id}&cookie=${cookieToken}&imgSize=${ url: `/playlist/cover/update?id=${playlist_id}&cookie=${localStorage.getItem('cookie')}&imgSize=${imgSize.width
imgSize.width
}&imgX=0&imgY=0&timestamp=${Date.now()}`, }&imgX=0&imgY=0&timestamp=${Date.now()}`,
headers: { headers: {
'Content-Type': 'multipart/form-data', 'Content-Type': 'multipart/form-data',
@ -85,5 +72,6 @@
}) })
} }
</script> </script>
</body> </body>
</html> </html>

View File

@ -13,22 +13,7 @@
<script src="https://cdn.jsdelivr.net/npm/axios@0.26.1/dist/axios.min.js <script src="https://cdn.jsdelivr.net/npm/axios@0.26.1/dist/axios.min.js
"></script> "></script>
<script> <script>
async function checkStatus(key) {
const res = await axios({
url: `/login/qr/check?key=${key}&timestamp=${Date.now()}&noCookie=true`,
})
return res.data
}
async function getLoginStatus(cookie = '') {
const res = await axios({
url: `/login/status?timestamp=${Date.now()}`,
method: 'post',
data: {
cookie,
},
})
document.querySelector('#info').innerText = JSON.stringify(res.data, null, 2)
}
async function login() { async function login() {
let timer let timer
let timestamp = Date.now() let timestamp = Date.now()
@ -59,6 +44,23 @@
}, 3000) }, 3000)
} }
login() login()
async function checkStatus(key) {
const res = await axios({
url: `/login/qr/check?key=${key}&timestamp=${Date.now()}&noCookie=true`,
})
return res.data
}
async function getLoginStatus(cookie = '') {
const res = await axios({
url: `/login/status?timestamp=${Date.now()}`,
method: 'post',
data: {
cookie,
},
})
document.querySelector('#info').innerText = JSON.stringify(res.data, null, 2)
}
</script> </script>
<style> <style>
.info { .info {

View File

@ -13,22 +13,6 @@
<script src="https://cdn.jsdelivr.net/npm/axios@0.26.1/dist/axios.min.js <script src="https://cdn.jsdelivr.net/npm/axios@0.26.1/dist/axios.min.js
"></script> "></script>
<script> <script>
async function checkStatus(key) {
const res = await axios({
url: `/login/qr/check?key=${key}&timestamp=${Date.now()}`,
})
return res.data
}
async function getLoginStatus(cookie = '') {
const res = await axios({
url: `/login/status?timestamp=${Date.now()}`,
method: 'post',
data: {
cookie,
},
})
document.querySelector('#info').innerText = JSON.stringify(res.data, null, 2)
}
async function login() { async function login() {
let timer let timer
let timestamp = Date.now() let timestamp = Date.now()
@ -59,6 +43,23 @@
}, 3000) }, 3000)
} }
login() login()
async function checkStatus(key) {
const res = await axios({
url: `/login/qr/check?key=${key}&timestamp=${Date.now()}`,
})
return res.data
}
async function getLoginStatus(cookie = '') {
const res = await axios({
url: `/login/status?timestamp=${Date.now()}`,
method: 'post',
data: {
cookie,
},
})
document.querySelector('#info').innerText = JSON.stringify(res.data, null, 2)
}
</script> </script>
<style> <style>
.info { .info {

View File

@ -1,63 +0,0 @@
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>test</title>
</head>
<body>
<p>请在控制台看结果</p>
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/axios/0.18.0/axios.min.js"></script>
<script>
const phone = ''
const password = ''
if (!phone || !password) {
const msg = '请设置你的手机号码和密码'
alert(msg)
throw new Error(msg)
}
$.ajax({
url: `/login/cellphone?phone=${phone}&password=${password}`,
xhrFields: {
withCredentials: true, //跨域的话必须设置
},
success: function (data) {
console.log(data)
$.ajax({
url: `/recommend/resource `,
xhrFields: {
withCredentials: true, //跨域的话必须设置
},
success: function (data) {
console.log(data)
},
error: function (err) {
console.log(err)
},
})
},
error: function (err) {
console.log(err)
},
})
axios({
url: `/login/cellphone?phone=${phone}&password=${password}`,
withCredentials: true, //跨域的话必须设置
}).then(function (res) {
console.log(res.data)
axios({
url: `/recommend/resource`,
withCredentials: true, //跨域的话必须设置
}).then(function (res) {
console.log(res.data)
})
})
</script>
</body>
</html>

View File

@ -8,6 +8,11 @@
</head> </head>
<body> <body>
<div>
<a href="/qrlogin-nocookie.html">
如果没登录,请先登录
</a>
</div>
<div id="app"> <div id="app">
<ul> <ul>
<li v-for="(item,index) in voicelist" @click="currentVoiceIndex=index" <li v-for="(item,index) in voicelist" @click="currentVoiceIndex=index"
@ -61,31 +66,10 @@
const file = document.querySelector('input[type=file]').files[0] const file = document.querySelector('input[type=file]').files[0]
this.upload(file) this.upload(file)
}, },
async login() {
const phone = '' // 这里填手机号
const password = '' // 这里填密码
const fileUpdateTime = {}
let fileLength = 0
if (!phone || !password) {
const msg = '请设置你的手机号码和密码'
alert(msg)
throw new Error(msg)
}
const res = await axios({
url: `/login/cellphone`,
method: 'post',
data: {
phone,
password,
},
})
this.cookieToken = res.data.cookie
},
async getData() { async getData() {
await this.login()
const res = await axios({ const res = await axios({
url: `/voicelist/search?cookie=${this.cookieToken}`, url: `/voicelist/search?cookie=${localStorage.getItem('cookie')}`,
}) })
console.log(res.data.data) console.log(res.data.data)
@ -103,14 +87,10 @@
formData.append('songFile', file) formData.append('songFile', file)
axios({ axios({
method: 'post', method: 'post',
url: `/voice/upload?time=${Date.now()}&cookie=${ url: `/voice/upload?time=${Date.now()}&cookie=${localStorage.getItem('cookie')
this.cookieToken }&songName=${this.songName}&voiceListId=${this.currentVoice.voiceListId
}&songName=${this.songName}&voiceListId=${ }&categoryId=${this.currentVoice.categoryId}&coverImgId=${this.currentVoice.coverImgId
this.currentVoice.voiceListId }&secondCategoryId=${this.currentVoice.secondCategoryId}&description=${this.description
}&categoryId=${this.currentVoice.categoryId}&coverImgId=${
this.currentVoice.coverImgId
}&secondCategoryId=${this.currentVoice.secondCategoryId}&description=${
this.description
}&privacy=1`, }&privacy=1`,
headers: { headers: {
'Content-Type': 'multipart/form-data', 'Content-Type': 'multipart/form-data',