feat: 新增云贝任务相关接口

This commit is contained in:
MoeFurina
2026-08-05 18:11:31 +08:00
parent 4045f1ad3f
commit a898e1d86c
15 changed files with 1066 additions and 96 deletions
+19 -12
View File
@@ -1,15 +1,16 @@
// 易盾反作弊 Token 注册端点
// 调用后获取实时 token 并存入共享存储,供后续带 checkToken 的请求使用
//
// GET /register/checktoken → 返回当前 token(尚无则自动获取)
// POST /register/checktoken → 强制刷新 token
// GET /register/checktoken?refresh=1 → 强制刷新
// GET /register/checktoken/v3 → 实时获取新 token(不缓存)
// POST /register/checktoken/v3 → 实时获取新 token
//
// 注意:每次获取都不缓存,模拟真实客户端每次请求使用新鲜 token,
// 避免反作弊 token 复用触发风控。
//
const { default: axios } = require('axios')
const { APP_CONF } = require('../util/config.json')
const URL = APP_CONF.dunDomainV3 + '/v3/b?pn=YD00000558929251'
let _token = ''
async function fetch() {
const res = await axios.get(URL, { timeout: 10000 })
@@ -19,13 +20,13 @@ async function fetch() {
throw new Error('易盾返回异常: ' + body.substring(0, 100))
}
// 端点处理
module.exports = async (query) => {
const refresh = query.refresh === '1' || query.refresh === 'true'
let token = refresh ? null : _token
if (!token) {
// 端点处理:每次实时获取新 token
module.exports = async () => {
let token = ''
try {
token = await fetch()
_token = token
} catch (e) {
// token 获取失败时返回空,由调用方决定是否重试
}
return {
status: 200,
@@ -33,5 +34,11 @@ module.exports = async (query) => {
}
}
// 给 request.js 读取用
module.exports.getToken = () => _token
// 给 request.js 读取用:每次调用实时获取新 token,不缓存
module.exports.getToken = async () => {
try {
return await fetch()
} catch (e) {
return ''
}
}