274 lines
11 KiB
JavaScript
274 lines
11 KiB
JavaScript
const axios = require('axios');
|
||
const qs = require('qs');
|
||
|
||
const API = 'https://huodong3.3839.com/n/hykb/grow/ajax.php';
|
||
const DAILY_URL = 'https://huodong3.3839.com/n/hykb/grow/daily.php';
|
||
|
||
const ACTION = {
|
||
DAILY_LOGIN: 'Dailylogin',
|
||
DAILY_SHARE: 'DailyShare',
|
||
DAILY_SHARE_CALLBACK: 'DailyShareCallb',
|
||
DAILY_GAME_LING: 'DailyGameLing',
|
||
DAILY_GAME_PLAY: 'DailyGamePlay',
|
||
DAILY_APP_LING: 'DailyAppLing',
|
||
DAILY_DATI: 'DailyDati',
|
||
DAILY_DATI_ANSWER: 'DailyDatiAnswer',
|
||
DAILY_DATI_ID: 4,
|
||
DAILY_GAME_CATE_JUMP: 'DailyGameCateJump',
|
||
DAILY_WATERING: 'Watering'
|
||
};
|
||
|
||
// const HYKB_SCOOKIE = process.env.HYKB_SCOOKIE;
|
||
// const HYKB_DEVICE_ID = process.env.HYKB_DEVICE_ID;
|
||
|
||
const HYKB_SCOOKIE = "5|0|38524686|cmFpbmVyb3Npb24=|kb2318B047E13AB3BAC4C9E36B388B6260|7vcwpJVjplVWoJIUpl6xITZO7j9c7lIn7v7OGv6Aov6=%1|2f18a0f2283ce7f6804281632ccdef22";
|
||
const HYKB_DEVICE_ID = "kb2318B047E13AB3BAC4C9E36B388B6260";
|
||
|
||
const headers = {
|
||
'Host': 'huodong3.3839.com',
|
||
'Accept': 'application/json, text/javascript, */*; q=0.01',
|
||
'X-Requested-With': 'XMLHttpRequest',
|
||
'User-Agent': 'Mozilla/5.0 (Linux; Android 13; RMX3562 Build/TP1A.220905.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/103.0.5060.129 Mobile Safari/537.36Androidkb/1.5.6.903(android;RMX3562;13;1080x2316;4G);@4399_sykb_android_activity@',
|
||
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
|
||
'Origin': 'https://huodong3.3839.com',
|
||
'Sec-Fetch-Site': 'same-origin',
|
||
'Sec-Fetch-Mode': 'cors',
|
||
'Sec-Fetch-Dest': 'empty',
|
||
'Referer': 'https://huodong3.3839.com/n/hykb/grow/daily.php',
|
||
'Accept-Encoding': 'gzip, deflate',
|
||
'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
|
||
// 'Cookie': process.env.HYKB_COOKIE
|
||
};
|
||
|
||
async function postApiData(url, data, headers) {
|
||
try {
|
||
let axiosConfig = {
|
||
method: 'post',
|
||
maxBodyLength: Infinity,
|
||
url: url,
|
||
headers: headers,
|
||
data: data
|
||
};
|
||
let response = await axios.request(axiosConfig);
|
||
if (response.status >= 200 && response.status < 300) {
|
||
let jsonData = response.data;
|
||
// console.log('JSON Data:', JSON.stringify(jsonData));
|
||
return jsonData
|
||
} else {
|
||
console.error('Request was not successful. Status:', response.status);
|
||
return null;
|
||
}
|
||
} catch (error) {
|
||
console.error('Error:', error.message);
|
||
return null;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* random
|
||
* @returns
|
||
*/
|
||
function generateRandom() {
|
||
const randomNum = Math.random();
|
||
return randomNum.toFixed(17);
|
||
}
|
||
|
||
function isFalsy(value) {
|
||
return !value;
|
||
}
|
||
|
||
async function sleep(ms) {
|
||
console.log("等待" + (ms / 1000) + "秒后继续执行");
|
||
return new Promise(resolve => setTimeout(resolve, ms));
|
||
}
|
||
|
||
function buildData(action, id, scookie, deviceId, requireMode) {
|
||
let data;
|
||
if (isFalsy(id)) {
|
||
data = qs.stringify({
|
||
'ac': action,
|
||
'r': generateRandom(),
|
||
'scookie': scookie,
|
||
'device': deviceId
|
||
});
|
||
} else if (requireMode) {
|
||
data = qs.stringify({
|
||
'ac': action,
|
||
'id': id,
|
||
'mode': 'weixin',
|
||
'r': generateRandom(),
|
||
'scookie': scookie,
|
||
'device': deviceId
|
||
});
|
||
} else {
|
||
data = qs.stringify({
|
||
'ac': action,
|
||
'id': id,
|
||
'r': generateRandom(),
|
||
'scookie': scookie,
|
||
'device': deviceId
|
||
});
|
||
}
|
||
return data;
|
||
}
|
||
|
||
function checkParams(scookie, devices) {
|
||
if (!scookie || !devices) {
|
||
console.log('未设置HYKB_SCOOKIE或HYKB_DEVICE_ID环境变量,多个使用#分割');
|
||
process.exit(1); // 1 表示退出程序,可以使用其他值表示不同的退出状态
|
||
}
|
||
}
|
||
|
||
async function execTodayTask() {
|
||
checkParams(HYKB_SCOOKIE, HYKB_DEVICE_ID);
|
||
let cookies = HYKB_SCOOKIE.split('#');
|
||
let devices = HYKB_DEVICE_ID.split('#');
|
||
if (cookies.length !== devices.length) {
|
||
console.log('HYKB_SCOOKIE或HYKB_DEVICE_ID设置错误,数量不一致!');
|
||
process.exit(1);
|
||
}
|
||
for (let i = 0; i < cookies.length; i++) {
|
||
let scookie = cookies[i];
|
||
let deviceId = devices[i];
|
||
let response = await axios.get(DAILY_URL, {headers: headers});
|
||
// 获取每日数据
|
||
let dailyData = await postApiData(API, buildData(ACTION.DAILY_LOGIN, null, scookie, deviceId, false));
|
||
let dailyIdList = [];
|
||
if (dailyData.key === 'ok') {
|
||
dailyData.config.daily_user_Task
|
||
.filter(task => task.success === "2")
|
||
.map(task => task.rwid)
|
||
.forEach(rwid => dailyIdList.push(rwid));
|
||
} else if (dailyData.key === 'no_login') {
|
||
console.log("账号" + (i + 1) + "登录信息已失效");
|
||
continue;
|
||
}
|
||
if (response.status === 200) {
|
||
let html = response.data;
|
||
const shareRegexPattern = /DailyShare\((\d+)\)/g;
|
||
const gameRegexPattern = /DailyGameLing\((\d+)\)/g;
|
||
const appRegexPattern = /DailyAppLing\((\d+)\)/g;
|
||
|
||
// 每日浇水
|
||
await doWateringTask(scookie, deviceId);
|
||
|
||
// 分享任务
|
||
let dailyShareIdList = [...html.matchAll(shareRegexPattern)]
|
||
.filter(match => !dailyIdList.includes(match[1]))
|
||
.map(match => match[1]);
|
||
await doShareTask(dailyShareIdList, scookie, deviceId);
|
||
|
||
// 体验任务
|
||
let dailyGameIdList = [...html.matchAll(gameRegexPattern)]
|
||
.filter(match => !dailyIdList.includes(match[1]))
|
||
.map(match => match[1]);
|
||
await doGameTask(dailyGameIdList, scookie, deviceId);
|
||
|
||
let dailyAppIdList = [...html.matchAll(appRegexPattern)]
|
||
.filter(match => !dailyIdList.includes(match[1]))
|
||
.map(match => match[1]);
|
||
|
||
// 答题任务
|
||
await doDatiTask(scookie, deviceId);
|
||
console.log("任务结束");
|
||
}
|
||
}
|
||
}
|
||
async function doWateringTask(scookie, deviceId){
|
||
console.log("开始执行每日浇水任务");
|
||
let watering = await postApiData(API, buildData(ACTION.DAILY_WATERING, null, scookie, deviceId, false), headers);
|
||
if (watering.key === '501') {
|
||
console.log(JSON.stringify(watering))
|
||
console.log("开始执行每日浇水成功");
|
||
} else {
|
||
console.log(JSON.stringify(watering))
|
||
console.log("每日浇水任务失败,原因:" + watering.info);
|
||
}
|
||
}
|
||
|
||
async function doShareTask(idList, scookie, deviceId) {
|
||
for (const id of idList) {
|
||
// 执行分享前查询
|
||
let view = await postApiData(API, buildData(ACTION.DAILY_SHARE, id, scookie, deviceId, false), headers);
|
||
if (view.key === '501') {
|
||
await sleep(3000);
|
||
let taskName = view.share_title;
|
||
console.log("分享任务【" + taskName + "】正在执行");
|
||
let shareCallback = await postApiData(API, buildData(ACTION.DAILY_SHARE_CALLBACK, id, scookie, deviceId, true), headers);
|
||
if (shareCallback.key === '501') {
|
||
await sleep(3000);
|
||
// 领奖
|
||
let reward = await postApiData(API, buildData(ACTION.DAILY_SHARE, id, scookie, deviceId, false), headers);
|
||
if (reward.key === '503') {
|
||
let csd = reward.reward_csd_num;
|
||
let bmh = reward.reward_bmh_num;
|
||
console.log("分享任务【" + taskName + "】领取成功,成熟度+" + csd + "爆米花+" + bmh);
|
||
} else {
|
||
console.log(JSON.stringify(shareCallback));
|
||
console.log("分享任务【" + taskName + "】领奖失败, 失败原因:" + shareCallback.info);
|
||
}
|
||
} else {
|
||
console.log(JSON.stringify(shareCallback));
|
||
console.log("分享任务【" + taskName + "】分享失败, 失败原因:" + shareCallback.info);
|
||
}
|
||
} else {
|
||
console.log(JSON.stringify(view));
|
||
console.log("分享任务执行失败,任务id:" + id + "失败原因:" + view.info);
|
||
}
|
||
}
|
||
}
|
||
|
||
async function doGameTask(idList, scookie, deviceId) {
|
||
for (const id of idList) {
|
||
// 执行打开操作
|
||
console.log("下载体验任务[" + id + "]开始");
|
||
let view = await postApiData(API, buildData(ACTION.DAILY_GAME_PLAY, id, scookie, deviceId, false), headers);
|
||
if (view.key === '501') {
|
||
await sleep(180000);
|
||
// 领奖
|
||
let reward = await postApiData(API, buildData(ACTION.DAILY_GAME_LING, id, scookie, deviceId, false), headers);
|
||
if (reward.key === '503') {
|
||
let csd = reward.reward_csd_num;
|
||
let bmh = reward.reward_bmh_num;
|
||
console.log("下载体验任务[" + id + "]领取成功,成熟度+" + csd + "爆米花+" + bmh);
|
||
} else {
|
||
console.log(JSON.stringify(reward));
|
||
console.log("下载体验任务[" + id + "]领奖失败, 失败原因:" + reward.info);
|
||
}
|
||
} else {
|
||
console.log(JSON.stringify(view));
|
||
console.log("下载体验任务执行失败,任务id:" + id + "失败原因:" + view.info);
|
||
}
|
||
}
|
||
}
|
||
|
||
async function doDatiTask(scookie, deviceId) {
|
||
console.log("开始执行每日答题任务");
|
||
let dati = await postApiData(API, buildData(ACTION.DAILY_DATI, ACTION.DAILY_DATI_ID, scookie, deviceId, false), headers);
|
||
if (dati.key === '501') {
|
||
let answerData = buildData(ACTION.DAILY_DATI_ANSWER, ACTION.DAILY_DATI_ID, scookie, deviceId, false);
|
||
const optionKeys = Object.keys(dati).filter(key => key.startsWith('option'));
|
||
const randomOptionKey = optionKeys[Math.floor(Math.random() * optionKeys.length)];
|
||
answerData.option = dati[randomOptionKey];
|
||
let answer = await postApiData(API, answerData, headers);
|
||
if (answer.key === '501') {
|
||
await sleep(3000);
|
||
let result = await postApiData(API, buildData(ACTION.DAILY_DATI, ACTION.DAILY_DATI_ID, scookie, deviceId, false), headers);
|
||
if (result.key === '501') {
|
||
console.log("每日答题完成,随机选择的答案" + answerData.option);
|
||
} else {
|
||
console.log(JSON.stringify(result));
|
||
console.log("每日答题失败,原因:" + result.info);
|
||
}
|
||
} else {
|
||
console.log(JSON.stringify(answer));
|
||
console.log("每日答题失败,原因:" + answer.info);
|
||
}
|
||
} else {
|
||
console.log(JSON.stringify(dati));
|
||
console.log("每日答题失败,原因:" + dati.info);
|
||
}
|
||
|
||
}
|
||
|
||
execTodayTask() |