mirror of
https://gitlab.com/Binaryify/neteasecloudmusicapi.git
synced 2025-05-23 22:37:41 +08:00
refactor: 请求头无需传递content-type、os和appver
This commit is contained in:
parent
c1011b8602
commit
dd9ec456bf
@ -8,7 +8,7 @@ const tunnel = require('tunnel')
|
|||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const tmpPath = require('os').tmpdir()
|
const tmpPath = require('os').tmpdir()
|
||||||
const { cookieToJson, cookieObjToString } = require('./index')
|
const { cookieToJson, cookieObjToString, toBoolean } = require('./index')
|
||||||
const anonymous_token = fs.readFileSync(
|
const anonymous_token = fs.readFileSync(
|
||||||
path.resolve(tmpPath, './anonymous_token'),
|
path.resolve(tmpPath, './anonymous_token'),
|
||||||
'utf-8',
|
'utf-8',
|
||||||
@ -34,13 +34,7 @@ const createRequest = (uri, data, options) => {
|
|||||||
const cookie = options.cookie || {}
|
const cookie = options.cookie || {}
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
options.headers = options.headers || {}
|
options.headers = options.headers || {}
|
||||||
let headers = {
|
let headers = options.headers
|
||||||
...options.headers,
|
|
||||||
'User-Agent': options.ua || chooseUserAgent(options.uaType),
|
|
||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
|
||||||
os: cookie.os || 'ios',
|
|
||||||
appver: cookie.appver || (cookie.os != 'pc' ? iosAppVersion : ''),
|
|
||||||
}
|
|
||||||
let ip = options.realIP || options.ip || ''
|
let ip = options.realIP || options.ip || ''
|
||||||
// console.log(ip)
|
// console.log(ip)
|
||||||
if (ip) {
|
if (ip) {
|
||||||
@ -91,7 +85,7 @@ const createRequest = (uri, data, options) => {
|
|||||||
// 根据加密方式加密请求数据;目前任意uri都支持四种加密方式
|
// 根据加密方式加密请求数据;目前任意uri都支持四种加密方式
|
||||||
switch (crypto) {
|
switch (crypto) {
|
||||||
case 'weapi':
|
case 'weapi':
|
||||||
headers['Referer'] = 'https://music.163.com'
|
headers['Referer'] = APP_CONF.domain
|
||||||
headers['User-Agent'] = options.ua || chooseUserAgent('pc')
|
headers['User-Agent'] = options.ua || chooseUserAgent('pc')
|
||||||
data.csrf_token = csrfToken
|
data.csrf_token = csrfToken
|
||||||
encryptData = encrypt.weapi(data)
|
encryptData = encrypt.weapi(data)
|
||||||
@ -136,8 +130,9 @@ const createRequest = (uri, data, options) => {
|
|||||||
encodeURIComponent(key) + '=' + encodeURIComponent(header[key]),
|
encodeURIComponent(key) + '=' + encodeURIComponent(header[key]),
|
||||||
)
|
)
|
||||||
.join('; ')
|
.join('; ')
|
||||||
|
headers['User-Agent'] = options.ua || chooseUserAgent(options.uaType)
|
||||||
|
|
||||||
let eapi = () => {
|
if (crypto === 'eapi') {
|
||||||
// 使用eapi加密
|
// 使用eapi加密
|
||||||
data.header = header
|
data.header = header
|
||||||
data.e_r =
|
data.e_r =
|
||||||
@ -146,19 +141,14 @@ const createRequest = (uri, data, options) => {
|
|||||||
: data.e_r != undefined
|
: data.e_r != undefined
|
||||||
? data.e_r
|
? data.e_r
|
||||||
: APP_CONF.encryptResponse // 用于加密接口返回值
|
: APP_CONF.encryptResponse // 用于加密接口返回值
|
||||||
|
data.e_r = toBoolean(data.e_r)
|
||||||
encryptData = encrypt.eapi(uri, data)
|
encryptData = encrypt.eapi(uri, data)
|
||||||
url = APP_CONF.apiDomain + '/eapi/' + uri.substr(5)
|
url = APP_CONF.apiDomain + '/eapi/' + uri.substr(5)
|
||||||
}
|
} else if (crypto === 'api') {
|
||||||
let api = () => {
|
|
||||||
// 不使用任何加密
|
// 不使用任何加密
|
||||||
url = APP_CONF.apiDomain + uri
|
url = APP_CONF.apiDomain + uri
|
||||||
encryptData = data
|
encryptData = data
|
||||||
}
|
}
|
||||||
if (crypto === 'eapi') {
|
|
||||||
eapi()
|
|
||||||
} else if (crypto === 'api') {
|
|
||||||
api()
|
|
||||||
}
|
|
||||||
break
|
break
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user