修复请求接口提示需要验证的问题 #1541 #1539 #1537 #1538

This commit is contained in:
binaryify 2022-05-29 01:11:37 +08:00
parent 844dabeeff
commit 1a3a9d3df6
3 changed files with 13 additions and 6 deletions

View File

@ -1,4 +1,7 @@
# 更新日志
### 4.6.0 | 2022.05.29
- 修复请求接口提示需要验证的问题 [#1541](https://github.com/Binaryify/NeteaseCloudMusicApi/issues/1541)
### 4.5.14 | 2022.05.06
- 修复获取歌单所有歌曲接口分页问题 [#1524](https://github.com/Binaryify/NeteaseCloudMusicApi/pull/1524)

View File

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

View File

@ -5,6 +5,7 @@ const http = require('http')
const https = require('https')
const tunnel = require('tunnel')
const { URLSearchParams, URL } = require('url')
const config = require('../util/config.json')
// request.debug = true // 开启可看到更详细信息
const chooseUserAgent = (ua = false) => {
@ -50,7 +51,11 @@ const createRequest = (method, url, data, options) => {
headers['Referer'] = 'https://music.163.com'
if (options.realIP) headers['X-Real-IP'] = options.realIP
// headers['X-Real-IP'] = '118.88.88.88'
if (typeof options.cookie === 'object')
if (typeof options.cookie === 'object') {
if (!options.cookie.MUSIC_U) {
// 匿名
options.cookie.MUSIC_A = config.anonymous_token
}
headers['Cookie'] = Object.keys(options.cookie)
.map(
(key) =>
@ -59,11 +64,10 @@ const createRequest = (method, url, data, options) => {
encodeURIComponent(options.cookie[key]),
)
.join('; ')
else if (options.cookie) headers['Cookie'] = options.cookie
if (!headers['Cookie']) {
headers['Cookie'] = options.token || ''
} else if (options.cookie) {
headers['Cookie'] = options.cookie
}
console.log(options.cookie, headers['Cookie'])
if (options.crypto === 'weapi') {
let csrfToken = (headers['Cookie'] || '').match(/_csrf=([^(;|$)]+)/)
data.csrf_token = csrfToken ? csrfToken[1] : ''