mirror of
https://gitlab.com/Binaryify/neteasecloudmusicapi.git
synced 2025-05-23 22:37:41 +08:00
refactor: 请求的data不覆盖
This commit is contained in:
parent
93ebc9cf51
commit
f7132eba63
@ -2,7 +2,7 @@
|
||||
|
||||
// 实际请求参数如下, 部分内容省略, 敏感信息已进行混淆
|
||||
// 可按需修改此 API 的代码
|
||||
/* {"extInfo":"{\"lastRequestTimestamp\":1692358373509,\"lbsInfoList\":[{\"lat\":40.23076381,\"lon\":129.07545186,\"time\":1692358543},{\"lat\":40.23076381,\"lon\":129.07545186,\"time\":1692055283}],\"listenedTs\":false,\"noAidjToAidj\":true}","header":"{}","e_r":true} */
|
||||
/* {"extInfo":"{\"lastRequestTimestamp\":1692358373509,\"lbsInfoList\":[{\"lat\":40.23076381,\"lon\":129.07545186,\"time\":1692358543},{\"lat\":40.23076381,\"lon\":129.07545186,\"time\":1692055283}],\"listenedTs\":false,\"noAidjToAidj\":true}","header":"{}"} */
|
||||
|
||||
const createOption = require('../util/option.js')
|
||||
module.exports = (query, request) => {
|
||||
|
@ -2,8 +2,14 @@ const createOption = require('../util/option.js')
|
||||
module.exports = (query, request) => {
|
||||
const method = query.method || 'POST'
|
||||
const uri = query.uri
|
||||
const data =
|
||||
typeof query.data === 'string' ? JSON.parse(query.data) : query.data || {}
|
||||
let data = {}
|
||||
try {
|
||||
data =
|
||||
typeof query.data === 'string' ? JSON.parse(query.data) : query.data || {}
|
||||
} catch (e) {
|
||||
data = {}
|
||||
}
|
||||
|
||||
const crypto = query.crypto || ''
|
||||
|
||||
const res = request(method, uri, data, createOption(query, crypto))
|
||||
|
@ -86,18 +86,19 @@ const createRequest = (method, uri, data = {}, options) => {
|
||||
// console.log(options.cookie, headers['Cookie'])
|
||||
|
||||
let url = ''
|
||||
let encryptData = ''
|
||||
// 目前任意uri都支持三种加密方式
|
||||
if (options.crypto === 'weapi') {
|
||||
headers['Referer'] = 'https://music.163.com'
|
||||
headers['User-Agent'] = options.ua || chooseUserAgent('pc')
|
||||
let csrfToken = (headers['Cookie'] || '').match(/_csrf=([^(;|$)]+)/)
|
||||
data.csrf_token = csrfToken ? csrfToken[1] : ''
|
||||
data = encrypt.weapi(data)
|
||||
encryptData = encrypt.weapi(data)
|
||||
url = APP_CONF.domain + '/weapi/' + uri.substr(5)
|
||||
} else if (options.crypto === 'linuxapi') {
|
||||
headers['User-Agent'] =
|
||||
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36'
|
||||
data = encrypt.linuxapi({
|
||||
encryptData = encrypt.linuxapi({
|
||||
method: method,
|
||||
url: APP_CONF.apiDomain + uri,
|
||||
params: data,
|
||||
@ -137,18 +138,22 @@ const createRequest = (method, uri, data = {}, options) => {
|
||||
|
||||
let eapiEncrypt = () => {
|
||||
data.header = header
|
||||
data = encrypt.eapi(uri, data)
|
||||
encryptData = encrypt.eapi(uri, data)
|
||||
url = APP_CONF.apiDomain + '/eapi/' + uri.substr(5)
|
||||
}
|
||||
if (options.crypto === 'eapi') {
|
||||
eapiEncrypt()
|
||||
} else if (options.crypto === 'api') {
|
||||
url = APP_CONF.apiDomain + uri
|
||||
encryptData = data
|
||||
} else if (options.crypto === '') {
|
||||
// 加密方式为空,以配置文件的加密方式为准
|
||||
if (APP_CONF.encrypt) {
|
||||
eapiEncrypt()
|
||||
} else url = APP_CONF.apiDomain + uri
|
||||
} else {
|
||||
url = APP_CONF.apiDomain + uri
|
||||
encryptData = data
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 未知的加密方式
|
||||
@ -160,7 +165,7 @@ const createRequest = (method, uri, data = {}, options) => {
|
||||
method: method,
|
||||
url: url,
|
||||
headers: headers,
|
||||
data: new URLSearchParams(data).toString(),
|
||||
data: new URLSearchParams(encryptData).toString(),
|
||||
httpAgent: new http.Agent({ keepAlive: true }),
|
||||
httpsAgent: new https.Agent({ keepAlive: true }),
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user