diff --git a/sign.js b/sign.js index 86e8d80..7b61517 100644 --- a/sign.js +++ b/sign.js @@ -1,5 +1,7 @@ const axios = require('axios'); const qs = require('qs'); +const {parse} = require("qs"); +const {post} = require("axios"); const API = 'https://huodong3.3839.com/n/hykb/grow/ajax.php'; const DAILY_URL = 'https://huodong3.3839.com/n/hykb/grow/daily.php'; @@ -19,13 +21,12 @@ const ACTION = { GOU_MAI: 'GouMai', // 购买种子 PLANT_SOW: 'PlantSow', // 种植 PLANT_RIPE: 'PlantRipe', //收割 + PRODUCE: 'Produce', // 查询爆米花数量 + START_PRODUCE: 'StartProduce', //兑换爆米花 }; -// 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 HYKB_SCOOKIE = process.env.HYKB_SCOOKIE; +const HYKB_DEVICE_ID = process.env.HYKB_DEVICE_ID; const headers = { 'Host': 'huodong3.3839.com', @@ -54,9 +55,8 @@ async function postApiData(url, data, headers) { }; 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 + return response.data } else { console.error('Request was not successful. Status:', response.status); return null; @@ -146,6 +146,7 @@ async function execTodayTask() { 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') { let seed = dailyData.config.seed; // 种子数量 @@ -154,12 +155,17 @@ async function execTodayTask() { let baomihua = dailyData.config.baomihua; // 爆米花数量 let username = dailyData.config.name; - let uid = dailyData.config.name; dailyData.config.daily_user_Task .filter(task => task.success === "2") .map(task => task.rwid) .forEach(rwid => dailyIdList.push(rwid)); - console.log("账号" + username + "(" + uid + ")任务开始执行"); + console.log(`账号${username},爆米花${baomihua}个,玉米${corn}个,任务开始执行`); + + if (chengshoudu === 100) { + // 收割、兑换、种植 + await doPlantTask(scookie, deviceId, seed); + } + } else if (dailyData.key === 'no_login') { console.log("账号" + (i + 1) + "登录信息已失效"); continue; @@ -233,6 +239,10 @@ async function doShareTask(idList, scookie, deviceId) { console.log(JSON.stringify(shareCallback)); console.log("分享任务【" + taskName + "】分享失败, 失败原因:" + shareCallback.info); } + } else if (view.key === '503') { + let csd = view.reward_csd_num; + let bmh = view.reward_bmh_num; + console.log("分享任务领取成功,成熟度+" + csd + "爆米花+" + bmh); } else { console.log(JSON.stringify(view)); console.log("分享任务执行失败,任务id:" + id + "失败原因:" + view.info); @@ -257,6 +267,10 @@ async function doGameTask(idList, scookie, deviceId) { console.log(JSON.stringify(reward)); console.log("下载体验任务[" + id + "]领奖失败, 失败原因:" + reward.info); } + } else if (view.key === '503') { + let csd = view.reward_csd_num; + let bmh = view.reward_bmh_num; + console.log("分享任务领取成功,成熟度+" + csd + "爆米花+" + bmh); } else { console.log(JSON.stringify(view)); console.log("下载体验任务执行失败,任务id:" + id); @@ -271,7 +285,7 @@ async function doDatiTask(scookie, deviceId) { 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]; + answerData += "&option=" + dati[randomOptionKey]; let answer = await postApiData(API, answerData, headers); if (answer.key === '501') { await sleep(3000); @@ -308,10 +322,75 @@ async function doHarvestTask(scookie, deviceId) { * 种植 * @param scookie * @param deviceId + * @param seed * @returns {Promise} */ -async function doPlantTask(scookie, deviceId) { +async function doPlantTask(scookie, deviceId, seed) { + let ripe = await postApiData(API, buildData(ACTION.PLANT_RIPE, null, scookie, deviceId, false), headers); + // console.log(JSON.stringify(ripe)); + if (ripe && ripe.key === '513') { + console.log(`收割成功,获得爆米花${ripe.add_corn}个`); + } + // 兑换爆米花 + await productBmh(scookie, deviceId); + if (parseInt(seed) === 0) { + // 购买种子 + let goumai = await postApiData(API, buildData(ACTION.GOU_MAI, null, scookie, deviceId, false), headers); + if (goumai && goumai.key === '503' && goumai.need_bmh <= parseInt(goumai.baomihua)) { + let data = qs.stringify({ + 'ac': action, + 'r': generateRandom(), + 'scookie': scookie, + 'device': deviceId, + 'resure': 1, + 'gmmode': 'seed', + 'tmpNum': 1 + }); + let resureGm = await postApiData(API, data, headers); + if (resureGm && resureGm.key === 'ok') { + console.log('种子购买成功'); + } else { + console.log('种子购买失败'); + } + } + } + // 种植 + let sow = await postApiData(API, buildData(ACTION.PLANT_SOW, null, scookie, deviceId, false), headers); + if (sow && sow.key === 'ok') { + console.log("播种完成"); + } +} + +async function productBmh(scookie, deviceId) { + + let produce = await postApiData(API, buildData(ACTION.PRODUCE, null, scookie, deviceId, false), headers); + // console.log(JSON.stringify(produce)); + if (produce && produce.key === 'ok' && parseInt(produce.corn) >= 1) { + let data = qs.stringify({ + 'ac': ACTION.START_PRODUCE, + 'r': generateRandom(), + 'scookie': scookie, + 'device': deviceId, + 'resure': 0, + 'preNum': produce.corn + }); + let startProduct = await postApiData(API, data, headers); + if (startProduct && startProduct.key === '502') { + let data = qs.stringify({ + 'ac': ACTION.START_PRODUCE, + 'r': generateRandom(), + 'scookie': scookie, + 'device': deviceId, + 'resure': 1, + 'preNum': produce.corn + }); + let finish = await postApiData(API, data, headers); + if (finish && finish.key === 'ok') { + console.log(`兑换成功,获得爆米花${finish.add_bmh},拥有爆米花${finish.baomihua}`); + } + } + } } -execTodayTask() \ No newline at end of file +execTodayTask(); \ No newline at end of file