kuaibao/daily.js

115 lines
4.2 KiB
JavaScript

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();