mirror of
https://github.com/XiaoGe-LiBai/yangmao.git
synced 2025-12-17 03:58:13 +08:00
Create 包子公益站.js
This commit is contained in:
179
包子公益站.js
Normal file
179
包子公益站.js
Normal file
@@ -0,0 +1,179 @@
|
||||
|
||||
const axios = require('axios');
|
||||
|
||||
// 环境变量名称
|
||||
const TOKEN_ENV_VAR = 'BAOZI_TOKEN';
|
||||
|
||||
// API 端点
|
||||
const API_SIGN = 'https://lucky.5202030.xyz/api/sign/';
|
||||
const API_LOTTERY = 'https://lucky.5202030.xyz/api/lottery/';
|
||||
|
||||
// 两次抽奖之间的延迟(毫秒),避免请求过快
|
||||
const LOTTERY_DELAY_MS = 200;
|
||||
// 抽奖安全锁:防止无限循环,单次运行最多抽这么多次
|
||||
const MAX_LOTTERY_ATTEMPTS = 200;
|
||||
|
||||
// 从环境变量读取 Token
|
||||
const AUTH_TOKEN = process.env[TOKEN_ENV_VAR];
|
||||
|
||||
if (!AUTH_TOKEN) {
|
||||
console.error(`❌ 错误:未找到环境变量 ${TOKEN_ENV_VAR}。`);
|
||||
console.log('请在青龙面板 "环境变量" 中添加此变量,值为你的 Authorization Token (包含 "Bearer ")。');
|
||||
process.exit(1); // 退出脚本
|
||||
}
|
||||
|
||||
// 统一的请求头
|
||||
const HEADERS = {
|
||||
'accept': 'application/json, text/plain, */*',
|
||||
'authorization': AUTH_TOKEN,
|
||||
'cache-control': 'no-cache',
|
||||
'pragma': 'no-cache',
|
||||
'origin': 'https://lucky.5202030.xyz',
|
||||
'user-agent': 'QingLong_Script_NodeJS/1.0', // 伪装一个 User Agent
|
||||
};
|
||||
|
||||
// 简单的延迟函数
|
||||
function delay(ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
/**
|
||||
* 任务1:执行每日签到
|
||||
*/
|
||||
async function doSignIn() {
|
||||
console.log('--- 任务1: 开始执行每日签到(修炼) ---');
|
||||
try {
|
||||
const response = await axios.post(API_SIGN, null, { headers: HEADERS });
|
||||
|
||||
const data = response.data;
|
||||
if (data.success) {
|
||||
console.log(`✅ 签到成功: ${data.message}`);
|
||||
console.log(` - 获得奖励: ${data.reward}`);
|
||||
console.log(` - 当前余额: ${data.current_balance}`);
|
||||
} else {
|
||||
// 假设已签到也会返回 success: false 或特定的 message
|
||||
console.warn(`🔔 签到提示: ${data.message || '签到失败或已签到'}`);
|
||||
}
|
||||
} catch (error) {
|
||||
if (error.response) {
|
||||
console.error(`❌ 签到请求失败: ${error.response.status} - ${error.response.statusText}`);
|
||||
console.error(` - 响应内容: ${JSON.stringify(error.response.data)}`);
|
||||
} else {
|
||||
console.error(`❌ 签到时发生网络错误: ${error.message}`);
|
||||
}
|
||||
}
|
||||
console.log('--- 签到任务结束 ---\n');
|
||||
}
|
||||
|
||||
/**
|
||||
* 任务2:执行自动抽奖(直到次数用完)
|
||||
*/
|
||||
async function doLottery() {
|
||||
console.log('--- 任务2: 开始执行自动抽奖 ---');
|
||||
|
||||
// 抽奖统计
|
||||
const stats = {
|
||||
totalNet: 0,
|
||||
draws: 0,
|
||||
positiveDraws: 0,
|
||||
negativeDraws: 0,
|
||||
zeroDraws: 0,
|
||||
startBalance: null,
|
||||
endBalance: 0,
|
||||
};
|
||||
|
||||
let remainingAttempts = -1; // -1 表示尚未开始
|
||||
|
||||
for (let i = 1; i <= MAX_LOTTERY_ATTEMPTS; i++) {
|
||||
try {
|
||||
// 执行抽奖
|
||||
const response = await axios.post(API_LOTTERY, null, { headers: HEADERS });
|
||||
const data = response.data;
|
||||
|
||||
// 检查 API 返回是否成功
|
||||
if (data.success) {
|
||||
stats.draws++;
|
||||
stats.totalNet += data.net_change;
|
||||
stats.endBalance = data.current_balance;
|
||||
|
||||
if (stats.startBalance === null) {
|
||||
// 通过净变化推算初始余额
|
||||
stats.startBalance = data.current_balance - data.net_change;
|
||||
}
|
||||
|
||||
if (data.net_change > 0) stats.positiveDraws++;
|
||||
else if (data.net_change < 0) stats.negativeDraws++;
|
||||
else stats.zeroDraws++;
|
||||
|
||||
// 打印单次结果
|
||||
console.log(`[第 ${i} 抽] 结果: ${data.message} | 净变化: ${data.net_change} | 剩余次数: ${data.remaining_attempts}`);
|
||||
|
||||
// 检查剩余次数
|
||||
remainingAttempts = data.remaining_attempts;
|
||||
if (remainingAttempts === 0) {
|
||||
console.log('🎉 所有抽奖次数已用完。');
|
||||
break; // 正常结束循环
|
||||
}
|
||||
} else {
|
||||
// API 返回 success: false,例如“次数不足”
|
||||
console.warn(`🔔 抽奖提示: ${data.message || '抽奖API返回错误'}。 停止抽奖。`);
|
||||
break; // 异常,结束循环
|
||||
}
|
||||
|
||||
// 在两次请求间稍作等待
|
||||
await delay(LOTTERY_DELAY_MS);
|
||||
|
||||
} catch (error) {
|
||||
if (error.response) {
|
||||
console.error(`❌ 抽奖请求失败: ${error.response.status} - ${error.response.statusText}`);
|
||||
console.error(` - 响应内容: ${JSON.stringify(error.response.data)}`);
|
||||
} else {
|
||||
console.error(`❌ 抽奖时发生网络错误: ${error.message}`);
|
||||
}
|
||||
console.error('抽奖任务因错误而终止。');
|
||||
break; // 发生错误,终止循环
|
||||
}
|
||||
}
|
||||
|
||||
if (remainingAttempts > 0) {
|
||||
console.warn(`⚠️ 警告: 抽奖在达到 ${MAX_LOTTERY_ATTEMPTS} 次上限后停止,但可能仍有剩余次数。`);
|
||||
}
|
||||
|
||||
// 打印最终统计
|
||||
console.log('\n--- 抽奖统计报告 ---');
|
||||
if (stats.draws > 0) {
|
||||
console.log(` - 初始余额: ${stats.startBalance.toFixed(2)}`);
|
||||
console.log(` - 最终余额: ${stats.endBalance.toFixed(2)}`);
|
||||
console.log(` - 总计盈亏: ${stats.totalNet.toFixed(2)}`);
|
||||
console.log(` - 总抽奖数: ${stats.draws} 次`);
|
||||
console.log(` - 盈利次数: ${stats.positiveDraws} 次`);
|
||||
console.log(` - 亏损次数: ${stats.negativeDraws} 次`);
|
||||
console.log(` - 无变化: ${stats.zeroDraws} 次`);
|
||||
} else {
|
||||
console.log(' - 本次未执行任何有效抽奖。');
|
||||
}
|
||||
console.log('--- 自动抽奖任务结束 ---');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 主执行函数
|
||||
*/
|
||||
async function main() {
|
||||
console.log(`🚀 开始执行 Lucky XYZ 自动任务... (Token: ...${AUTH_TOKEN.slice(-10)})`);
|
||||
|
||||
// 1. 执行签到
|
||||
await doSignIn();
|
||||
|
||||
// 2. 执行抽奖
|
||||
await doLottery();
|
||||
|
||||
console.log('✅ 所有任务执行完毕。');
|
||||
}
|
||||
|
||||
// 运行主函数
|
||||
main().catch(error => {
|
||||
console.error('❌ 脚本执行过程中发生未捕获的致命错误:');
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user