Merge pull request #121 from shgdym/ma1n

This commit is contained in:
Faker 2023-07-17 21:20:51 +08:00 committed by GitHub
commit 9b48d41d4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -34,12 +34,9 @@ let cookiesArr = [],
//助力好友分享码(最多3个,否则后面的助力失败),原因:京东农场每人每天只有3次助力机会
//此此内容是IOS用户下载脚本到本地使用填写互助码的地方同一京东账号的好友互助码请使用@符号隔开。
//下面给出两个账号的填写示例iOS只支持2个京东账号
let shareCodes = [ // 这个列表填入你要助力的好友的shareCode
// //账号一的好友shareCode,不同好友的shareCode中间用@符号隔开
// '5853550f71014282912b76d95beb84c0@b58ddba3317b44ceb0ac86ea8952998c@8d724eb95e3847b6a1526587d1836f27@a80b7d1db41a4381b742232da9d22443@ce107b8f64d24f62a92292180f764018@c73ea563a77d4464b273503d3838fec1@0dd9a7fd1feb449fb1bf854a3ec0e801',
// //账号二的好友shareCode,不同好友的shareCode中间用@符号隔开
// '5853550f71014282912b76d95beb84c0@b58ddba3317b44ceb0ac86ea8952998c@8d724eb95e3847b6a1526587d1836f27@a80b7d1db41a4381b742232da9d22443@ce107b8f64d24f62a92292180f764018@c73ea563a77d4464b273503d3838fec1@0dd9a7fd1feb449fb1bf854a3ec0e801',
]
let codeType = 0;
const JD_ZLC_URL = process.env.JD_ZLC_URL ? process.env.JD_ZLC_URL : "https://zlc1.chaoyi996.com";
let message = '',
subTitle = '',
option = {},
@ -109,7 +106,7 @@ async function jdFruit() {
//console.log(`\n【京东账号${$.index}${$.UserName})的${$.name}好友互助码】${$.farmInfo.farmUserPro.shareCode}\n`);
console.log(`\n【已成功兑换水果】${$.farmInfo.farmUserPro.winTimes}\n`);
message += `【已兑换水果】${$.farmInfo.farmUserPro.winTimes}\n`;
//await masterHelpShare(); //助力好友
if ($.farmInfo.treeState === 2 || $.farmInfo.treeState === 3) {
option['open-url'] = urlSchema;
$.msg($.name, ``, `【京东账号${$.index}${$.nickName || $.UserName}\n【提醒⏰】${$.farmInfo.farmUserPro.name}已可领取\n请去京东APP或微信小程序查看\n点击弹窗即达`, option);
@ -134,6 +131,8 @@ async function jdFruit() {
await getTenWaterAward(); //领取10浇水奖励
await getWaterFriendGotAward(); //领取为2好友浇水奖励
await duck();
await shareCodesFormat();
await masterHelpShare(); //助力好友
if (!process.env.DO_TEN_WATER_AGAIN) {
console.log('执行再次浇水')
await doTenWaterAgain(); //再次浇水
@ -260,6 +259,153 @@ async function doDailyTask() {
await getExtraAward(); //领取额外水滴奖励
await turntableFarm() //天天抽奖得好礼
}
function shareCodesFormat() {
return new Promise(async (resolve) => {
// console.log(`第${$.index}个京东账号的助力码:::${$.shareCodesArr[$.index - 1]}`)
newShareCodes = [];
const readShareCodeRes = await readShareCode(jdFruitShareArr[$.index - 1]);
if (readShareCodeRes && readShareCodeRes.code === 200) {
newShareCodes = [...new Set([...newShareCodes, ...(readShareCodeRes.data || [])])];
}
console.log(`${$.index}个京东账号将要助力的好友${JSON.stringify(newShareCodes)}`)
resolve();
});
}
function readShareCode(code) {
return new Promise(async resolve => {
console.log(`当前使用助力池${JD_ZLC_URL}`)
$.get({ url: JD_ZLC_URL + `/farm?code=` + code, timeout: 10000, }, (err, resp, data) => {
try {
if (err) {
console.log(`${JSON.stringify(err)}`)
console.log(`${$.name} API请求失败请检查网路重试`)
} else {
if (data) {
console.log(`随机取20个码来助力`)
data = JSON.parse(data);
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve(data);
}
})
await $.wait(10000);
resolve()
})
}
async function masterHelpShare() {
console.log("开始助力好友");
let salveHelpAddWater = 0;
let remainTimes = 3; //今日剩余助力次数,默认3次京东农场每人每天3次助力机会
let helpSuccessPeoples = ""; //成功助力好友
console.log(`格式化后的助力码::${JSON.stringify(newShareCodes)}\n`);
helpStatisticArr = {}
helpStatisticArr['fromCode'] = $.farmInfo.farmUserPro.shareCode
helpStatisticArr['codeType'] = codeType;
helpStatisticArr['results'] = {};
helpStatisticStatus = 2
helpStatisticRemark = ''
for (let code of newShareCodes) {
console.log(`开始助力京东账号${$.index} - ${$.nickName || $.UserName}的好友: ${code}`);
if (!code) continue;
if (code === $.farmInfo.farmUserPro.shareCode) {
console.log("不能为自己助力哦跳过自己的shareCode\n");
continue;
}
// $.helpResult = await doWxApi("initForFarmWX", { shareCode: code, mpin: "", imageUrl: "", nickName: "", version, channel: 2, babelChannel: 0 }, 0);
await masterHelp(code);
if ($.helpResult.code === "0") {
if ($.helpResult.helpResult.code === "0") {
//助力成功
helpStatisticStatus = 1;
salveHelpAddWater += $.helpResult.helpResult.salveHelpAddWater;
console.log(`【助力好友结果】: 已成功给【${$.helpResult.helpResult.masterUserInfo.nickName}】助力`);
console.log(`给好友【${$.helpResult.helpResult.masterUserInfo.nickName}】助力获得${$.helpResult.helpResult.salveHelpAddWater}g水滴`);
helpSuccessPeoples += ($.helpResult.helpResult.masterUserInfo.nickName || "匿名用户") + ",";
} else if ($.helpResult.helpResult.code === "8") {
helpStatisticStatus = 3;
console.log(`【助力好友结果】: 助力【${$.helpResult.helpResult.masterUserInfo.nickName}】失败,您今天助力次数已耗尽`);
} else if ($.helpResult.helpResult.code === "9") {
helpStatisticStatus = 5;
console.log(`【助力好友结果】: 之前给【${$.helpResult.helpResult.masterUserInfo.nickName}】助力过了`);
} else if ($.helpResult.helpResult.code === "10") {
helpStatisticStatus = 4;
console.log(`【助力好友结果】: 好友【${$.helpResult.helpResult.masterUserInfo.nickName}】已满五人助力`);
} else {
helpStatisticStatus = 6;
helpStatisticRemark = JSON.stringify($.helpResult.helpResult)
console.log(`助力其他情况:${JSON.stringify($.helpResult.helpResult)}`);
}
console.log(`【今日助力次数还剩】${$.helpResult.helpResult.remainTimes}\n`);
remainTimes = $.helpResult.helpResult.remainTimes;
if ($.helpResult.helpResult.remainTimes === 0) {
console.log(`您当前助力次数已耗尽,跳出助力`);
if (!(helpStatisticStatus in helpStatisticArr['results'])) {
helpStatisticArr['results'][helpStatisticStatus] = [code]
} else {
helpStatisticArr['results'][helpStatisticStatus].push(code)
}
break;
}
} else {
helpStatisticStatus = 2;
helpStatisticRemark = JSON.stringify($.helpResult.helpResult)
console.log(`助力失败::${JSON.stringify($.helpResult)}`);
}
if (!(helpStatisticStatus in helpStatisticArr['results'])) {
helpStatisticArr['results'][helpStatisticStatus] = [code]
} else {
helpStatisticArr['results'][helpStatisticStatus].push(code)
}
}
helpStatisticArr['Remark'] = helpStatisticRemark;
console.log(`当前使用助力池${JD_ZLC_URL}`)
r = { url: `https://zlc1.chaoyi996.com/api/app/booster-code/submit-real-contribution`, body: JSON.stringify(helpStatisticArr), headers: { "Content-Type": "application/json" } };
$.post(r, (err, resp, data) => {
try {
if (err) {
console.log(`${JSON.stringify(err)}`)
console.log(`${$.name} 提交助力结果API请求失败`)
} else {
if (data) {
console.log(`提交成功`)
data = JSON.parse(data);
}
}
} catch (e) {
$.logErr(e, resp)
}
})
if ($.isLoon() || $.isQuanX() || $.isSurge()) {
let helpSuccessPeoplesKey = timeFormat() + $.farmInfo.farmUserPro.shareCode;
if (!$.getdata(helpSuccessPeoplesKey)) {
//把前一天的清除
$.setdata("", timeFormat(Date.now() - 24 * 60 * 60 * 1000) + $.farmInfo.farmUserPro.shareCode);
$.setdata("", helpSuccessPeoplesKey);
}
if (helpSuccessPeoples) {
if ($.getdata(helpSuccessPeoplesKey)) {
$.setdata($.getdata(helpSuccessPeoplesKey) + "," + helpSuccessPeoples, helpSuccessPeoplesKey);
} else {
$.setdata(helpSuccessPeoples, helpSuccessPeoplesKey);
}
}
helpSuccessPeoples = $.getdata(helpSuccessPeoplesKey);
}
if (helpSuccessPeoples && helpSuccessPeoples.length > 0) {
message += `【您助力的好友👬】${helpSuccessPeoples.substr(0, helpSuccessPeoples.length - 1)}\n`;
}
if (salveHelpAddWater > 0) {
// message += `【助力好友👬】获得${salveHelpAddWater}g💧\n`;
console.log(`【助力好友👬】获得${salveHelpAddWater}g💧\n`);
}
message += `【今日剩余助力👬】${remainTimes}\n`;
console.log("助力好友结束,即将开始领取额外水滴奖励\n");
}
async function getTreasureBoxAwardTask() {
await taskInitForFarm();
const treasureBox = $.farmTask['treasureBoxInit-getBean'];