style: 简化createOption

This commit is contained in:
ElyPrism 2026-07-15 21:06:50 +08:00
parent f527c1ef73
commit 321c25bd7d
No known key found for this signature in database
4 changed files with 19 additions and 15 deletions

View File

@ -1,11 +1,5 @@
// 获取广告 // 获取广告
// 基于逆向网易云音乐 v9.5.45 RN Hermes 源码:
// - adService.getAd() → Network.nativeRequest → /api/ad/get
// - 需要 X-antiCheatToken 易盾反作弊头
// - 使用 xeapi 加密
//
// 返回 extra.reqId 可用于 ad_listening_rights_gain 的 reqUid
//
const createOption = require('../util/option.js') const createOption = require('../util/option.js')
module.exports = async (query, request) => { module.exports = async (query, request) => {
@ -19,7 +13,7 @@ module.exports = async (query, request) => {
const res = await request(`/api/ad/get`, data, option) const res = await request(`/api/ad/get`, data, option)
const raw = res.body const raw = res.body
// 提取广告中的 req_id (用于领取权益) // 提取广告中的 req_id
let reqId = '' let reqId = ''
try { try {
if (raw?.ads) { if (raw?.ads) {

View File

@ -72,11 +72,11 @@ module.exports = async (query, request) => {
reqParam: JSON.stringify(rightsParam), reqParam: JSON.stringify(rightsParam),
} }
const option = createOption(query, 'xeapi') const res = await request(
// 关键: 开启 X-antiCheatToken 头 `/api/ad/listening/rights/gain`,
option.checkToken = true data,
createOption(query, 'xeapi', true),
const res = await request(`/api/ad/listening/rights/gain`, data, option) )
return { return {
status: 200, status: 200,

View File

@ -5473,12 +5473,22 @@ let data = encodeURIComponent(
**调用例子 :** `/song/cloud/download?id=123456789`' **调用例子 :** `/song/cloud/download?id=123456789`'
### 获取广告
说明 : 调用此接口, 可获取广告
**接口地址 :** `/ad/get`
**调用例子 :** `/ad/get`
### 获取30分钟免费听歌时长 ### 获取30分钟免费听歌时长
说明 : 登录后调用此接口, 获取30分钟免费听歌时长 说明 : 登录后调用此接口, 获取30分钟免费听歌时长
!> 警告: 通过调取接口出现的任何问题由调用者自行承担 !> 警告: 通过调取接口出现的任何问题由调用者自行承担
**可选参数 :** `reqUid` 通过`/ad/get` 获取的广告ID
**接口地址 :** `/ad/listening/rights/gain` **接口地址 :** `/ad/listening/rights/gain`
**调用例子 :** `/ad/listening/rights/gain` **调用例子 :** `/ad/listening/rights/gain`

View File

@ -1,4 +1,4 @@
const createOption = (query, crypto = '') => { const createOption = (query, crypto = '', checkToken = false) => {
return { return {
crypto: query.crypto || crypto || '', crypto: query.crypto || crypto || '',
cookie: query.cookie || process.env.NETEASE_COOKIE, cookie: query.cookie || process.env.NETEASE_COOKIE,
@ -11,7 +11,7 @@ const createOption = (query, crypto = '') => {
: ['true', true].includes(query.randomCNIP), : ['true', true].includes(query.randomCNIP),
e_r: query.e_r || undefined, e_r: query.e_r || undefined,
domain: query.domain || '', domain: query.domain || '',
checkToken: query.checkToken || false, checkToken: query.checkToken || checkToken,
headers: query.headers || {}, headers: query.headers || {},
timeout: query.timeout || 0, timeout: query.timeout || 0,
} }