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 path = require('path')
|
||||
const tmpPath = require('os').tmpdir()
|
||||
const { cookieToJson, cookieObjToString } = require('./index')
|
||||
const { cookieToJson, cookieObjToString, toBoolean } = require('./index')
|
||||
const anonymous_token = fs.readFileSync(
|
||||
path.resolve(tmpPath, './anonymous_token'),
|
||||
'utf-8',
|
||||
@ -34,13 +34,7 @@ const createRequest = (uri, data, options) => {
|
||||
const cookie = options.cookie || {}
|
||||
return new Promise((resolve, reject) => {
|
||||
options.headers = options.headers || {}
|
||||
let 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 headers = options.headers
|
||||
let ip = options.realIP || options.ip || ''
|
||||
// console.log(ip)
|
||||
if (ip) {
|
||||
@ -91,7 +85,7 @@ const createRequest = (uri, data, options) => {
|
||||
// 根据加密方式加密请求数据;目前任意uri都支持四种加密方式
|
||||
switch (crypto) {
|
||||
case 'weapi':
|
||||
headers['Referer'] = 'https://music.163.com'
|
||||
headers['Referer'] = APP_CONF.domain
|
||||
headers['User-Agent'] = options.ua || chooseUserAgent('pc')
|
||||
data.csrf_token = csrfToken
|
||||
encryptData = encrypt.weapi(data)
|
||||
@ -136,8 +130,9 @@ const createRequest = (uri, data, options) => {
|
||||
encodeURIComponent(key) + '=' + encodeURIComponent(header[key]),
|
||||
)
|
||||
.join('; ')
|
||||
headers['User-Agent'] = options.ua || chooseUserAgent(options.uaType)
|
||||
|
||||
let eapi = () => {
|
||||
if (crypto === 'eapi') {
|
||||
// 使用eapi加密
|
||||
data.header = header
|
||||
data.e_r =
|
||||
@ -146,19 +141,14 @@ const createRequest = (uri, data, options) => {
|
||||
: data.e_r != undefined
|
||||
? data.e_r
|
||||
: APP_CONF.encryptResponse // 用于加密接口返回值
|
||||
data.e_r = toBoolean(data.e_r)
|
||||
encryptData = encrypt.eapi(uri, data)
|
||||
url = APP_CONF.apiDomain + '/eapi/' + uri.substr(5)
|
||||
}
|
||||
let api = () => {
|
||||
} else if (crypto === 'api') {
|
||||
// 不使用任何加密
|
||||
url = APP_CONF.apiDomain + uri
|
||||
encryptData = data
|
||||
}
|
||||
if (crypto === 'eapi') {
|
||||
eapi()
|
||||
} else if (crypto === 'api') {
|
||||
api()
|
||||
}
|
||||
break
|
||||
|
||||
default:
|
||||
|
Loading…
x
Reference in New Issue
Block a user