diff --git a/daily.js b/daily.js deleted file mode 100644 index 1d173c9..0000000 --- a/daily.js +++ /dev/null @@ -1,115 +0,0 @@ -const axios = require('axios'); -const qs = require('qs'); -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 -}; -const api = 'https://huodong3.3839.com/n/hykb/grow/ajax.php'; -const daily_list_api = 'https://huodong3.3839.com/n/hykb/grow/daily.php'; - -const share_callback_action = 'DailyShareCallb'; -const share_daily_action = 'DailyShare'; - -/** - * random - * @returns - */ -function generateRandom() { - const randomNum = Math.random(); - return randomNum.toFixed(17); -} - -/** - * 获取数据 - * @param {*} action DailyShareCallb-分享回调 - * @param {*} id - */ -function getApiData(action, id) { - let data = qs.stringify({ - 'ac': action, - 'id': id, - 'mode': 'weixin', - 'r': generateRandom(), - 'scookie': process.env.HYKB_SCOOKIE, - 'device': process.env.HYKB_DEVICE - }); - let config = { - method: 'post', - maxBodyLength: Infinity, - url: api, - headers: headers, - data: data - }; - let json_data = null; - axios.request(config) - .then((response) => { - // console.log(JSON.stringify(response.data)); - let json_data = JSON.stringify(response.data); - if (action === share_callback_action && json_data && response.data['key'] === "501") { - config['data']['ac'] = share_daily_action; - axios.request(config) - .then((res) => { - let daily_json = JSON.stringify(res.data); - if (daily_json && res.data['key'] === "503") { - let csd = res.data['reward_csd_num']; - let today_csd = res.data['day_rw_csd']; - console.log("分享获得成熟度 " + csd + " 今日总共获取成熟度 " + today_csd); - } else { - console.log(JSON.stringify(data)); - console.log("执行领取任务失败,原始数据 => " + JSON.stringify(res.data) + " id => " + id); - } - }) - .catch((err) => { - console.log(err); - }); - } else { - console.log(JSON.stringify(data)); - console.log("执行分享任务失败,原始数据 => " + JSON.stringify(response.data) + " id => " + id); - } - }) - .catch((error) => { - console.log(error); - }); - return null; -} -function sleep(ms) { - return new Promise(resolve => setTimeout(resolve, ms)); -} - -async function main() { - let config = { - method: 'get', - url: daily_list_api, - headers: headers, - }; - let id_list = []; - let response = await axios.request(config); - let html = response.data; - // console.log(html); - //DailyGameLing、DailyAppLing、DailyGameCateLing、DailyDati、DailyFriendLing、DailyJiaoHu - const regexPattern = /DailyShare\((\d+)\)/g; - let matches = [...html.matchAll(regexPattern)]; // 进行全局匹配 - if (matches.length > 0) { - let values = matches.map(match => match[1]); // 获取所有匹配的数值部分 - console.log('Found values:', values); // 输出所有匹配到的数值 - for (const id of values) { - console.log("执行分享任务 id => " + id); - getApiData(share_callback_action, id); - await sleep(15000); - } - } else { - console.log('Values not found.'); - } -} -main(); \ No newline at end of file diff --git a/fileOperations.js b/fileOperations.js new file mode 100644 index 0000000..cf03c7d --- /dev/null +++ b/fileOperations.js @@ -0,0 +1,30 @@ +const fs = require("fs"); + +// 保存题目和答案到txt文件,但仅当题目不存在时保存 +function saveToFile(data) { + try { + const existingData = readFromFile(); // Read existing data + const newData = { ...existingData, ...data }; // Merge existing and new data + fs.writeFileSync("questions.txt", JSON.stringify(newData), "utf-8"); + console.log("Data saved to questions.txt"); + } catch (error) { + console.error("Error saving data:", error); + } +} + +// 从txt文件中读取题目和答案 +function readFromFile(question) { + try { + const data = fs.readFileSync("questions.txt", "utf-8"); + const savedData = JSON.parse(data); + if (question) { + return savedData[question] || "Question not found"; + } else { + return savedData; + } + } catch (error) { + console.error("Error reading file:", error); + return {}; + } +} +module.exports = { saveToFile, readFromFile }; \ No newline at end of file diff --git a/sign.js b/sign.js index 7b61517..fbf241f 100644 --- a/sign.js +++ b/sign.js @@ -1,8 +1,6 @@ const axios = require('axios'); const qs = require('qs'); -const {parse} = require("qs"); -const {post} = require("axios"); - +const {saveToFile, readFromFile} = require("./fileOperations"); const API = 'https://huodong3.3839.com/n/hykb/grow/ajax.php'; const DAILY_URL = 'https://huodong3.3839.com/n/hykb/grow/daily.php'; @@ -13,10 +11,12 @@ const ACTION = { DAILY_GAME_LING: 'DailyGameLing', DAILY_GAME_PLAY: 'DailyGamePlay', DAILY_APP_LING: 'DailyAppLing', + DAILY_APP_JUMP: 'DailyAppJump', DAILY_DATI: 'DailyDati', DAILY_DATI_ANSWER: 'DailyDatiAnswer', DAILY_DATI_ID: 4, DAILY_GAME_CATE_JUMP: 'DailyGameCateJump', + DAILY_GAME_CATE_LING: 'DailyGameCateLing', DAILY_WATERING: 'Watering', // 浇水 GOU_MAI: 'GouMai', // 购买种子 PLANT_SOW: 'PlantSow', // 种植 @@ -175,6 +175,7 @@ async function execTodayTask() { const shareRegexPattern = /DailyShare\((\d+)\)/g; const gameRegexPattern = /DailyGameLing\((\d+)\)/g; const appRegexPattern = /DailyAppLing\((\d+)\)/g; + const cateRegexPattern = /DailyGameCateLing\((\d+)\)/g; // 每日浇水 await doWateringTask(scookie, deviceId); @@ -194,6 +195,12 @@ async function execTodayTask() { let dailyAppIdList = [...html.matchAll(appRegexPattern)] .filter(match => !dailyIdList.includes(match[1])) .map(match => match[1]); + await doDailyAppJumpTask(dailyAppIdList, scookie, deviceId); + + let cateAppIdList = [...html.matchAll(cateRegexPattern)] + .filter(match => !dailyIdList.includes(match[1])) + .map(match => match[1]); + await doDailyGameCateJumpTask(cateAppIdList, scookie, deviceId); // 答题任务 await doDatiTask(scookie, deviceId); @@ -283,9 +290,14 @@ async function doDatiTask(scookie, deviceId) { 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 queryAnswer = readFromFile(dati.title); + if (queryAnswer) { + const optionKeys = Object.keys(dati).filter(key => key.startsWith('option')); + const randomOptionKey = optionKeys[Math.floor(Math.random() * optionKeys.length)]; + queryAnswer = dati[randomOptionKey]; + } + answerData += "&option=" + queryAnswer; let answer = await postApiData(API, answerData, headers); if (answer.key === '501') { await sleep(3000); @@ -293,6 +305,12 @@ async function doDatiTask(scookie, deviceId) { if (result.key === '501') { console.log(JSON.stringify(result)); console.log("每日答题完成,随机选择的答案" + answerData.option); + } else if (result.key === '503') { + //保存题目信息 + let backTimu = result.back_timu; + let question = {}; + question[backTimu] = result.back_answer; + saveToFile(question); } else { console.log(JSON.stringify(result)); console.log("每日答题失败,原因:" + result.info); @@ -308,16 +326,47 @@ async function doDatiTask(scookie, deviceId) { } -/** - * 收割 - * @param scookie - * @param deviceId - * @returns {Promise} - */ -async function doHarvestTask(scookie, deviceId) { - +async function doDailyAppJumpTask(idList, scookie, deviceId) { + for (const id of idList) { + let res = await postApiData(API, buildData(ACTION.DAILY_APP_JUMP, id, scookie, deviceId, false), headers); + if (res.key === 'ok') { + await sleep(180000); + let reward = await postApiData(API, buildData(ACTION.DAILY_APP_LING, id, scookie, deviceId, false), headers); + if (reward.key === '503') { + let csd = reward.reward_csd_num; + let bmh = reward.reward_bmh_num; + console.log("体验任务【在线玩频道】领取成功,成熟度+" + csd + "爆米花+" + bmh); + } else { + console.log(JSON.stringify(reward)); + console.log("体验任务【在线玩频道】领奖失败, 失败原因:" + reward.info); + } + } else { + console.log(JSON.stringify(res)); + console.log("任务执行失败,任务id:" + id + "失败原因:" + res.info); + } + } } +async function doDailyGameCateJumpTask(idList, scookie, deviceId) { + for (const id of idList) { + let res = await postApiData(API, buildData(ACTION.DAILY_GAME_CATE_JUMP, id, scookie, deviceId, false), headers); + if (res.key === 'ok') { + await sleep(180000); + let reward = await postApiData(API, buildData(ACTION.DAILY_GAME_CATE_LING, id, scookie, deviceId, false), headers); + if (reward.key === '503') { + let csd = reward.reward_csd_num; + let bmh = reward.reward_bmh_num; + console.log("体验任务【近期爆友热玩游戏】领取成功,成熟度+" + csd + "爆米花+" + bmh); + } else { + console.log(JSON.stringify(reward)); + console.log("体验任务【近期爆友热玩游戏】领奖失败, 失败原因:" + reward.info); + } + } else { + console.log(JSON.stringify(res)); + console.log("任务执行失败,任务id:" + id + "失败原因:" + res.info); + } + } +} /** * 种植 * @param scookie