Skip to content

Commit

Permalink
jd_bean_sign.js京豆签到兼容腾讯云函数,感谢github@ykrank提供的帮助
Browse files Browse the repository at this point in the history
  • Loading branch information
lxk0301 committed Nov 17, 2020
1 parent 03d6fbc commit dc5bf3b
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions jd_bean_sign.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
京豆签到,自用,可N个京东账号,IOS软件用户请使用 https://raw.githubusercontent.com/NobyDa/Script/master/JD-DailyBonus/JD_DailyBonus.js
Node.JS专用
更新时间:2020-11-09
更新时间:2020-11-17
从 github @ruicky改写而来
version v0.0.1
create by ruicky
Expand All @@ -14,8 +14,9 @@ const jdCookieNode = $.isNode() ? require('./jdCookie.js') : '';
const exec = require('child_process').execSync
const fs = require('fs')
const download = require('download');
const path = "./result.txt";
const JD_DailyBonusPath = "./JD_DailyBonus.js";
let resultPath = "./result.txt";
let JD_DailyBonusPath = "./JD_DailyBonus.js";
let outPutUrl = './';
let cookiesArr = [], cookie = '';

if ($.isNode()) {
Expand All @@ -29,9 +30,10 @@ if ($.isNode()) {
$.msg($.name, '【提示】请先获取cookie\n直接使用NobyDa的京东签到获取', 'https://bean.m.jd.com/', {"open-url": "https://bean.m.jd.com/"});
return;
}
await requireConfig();
// 下载最新代码
await downFile();
const content = await fs.readFileSync('./JD_DailyBonus.js', 'utf8')
const content = await fs.readFileSync(JD_DailyBonusPath, 'utf8')
for (let i =0; i < cookiesArr.length; i++) {
cookie = cookiesArr[i];
if (cookie) {
Expand All @@ -40,7 +42,7 @@ if ($.isNode()) {
$.nickName = '';
await TotalBean();
console.log(`*****************开始京东账号${$.index} ${$.nickName || $.UserName}京豆签到*******************\n`);
console.log(`⚠⚠⚠⚠⚠⚠⚠⚠ 如遇到Bark APP推送通知消息失败的,请换用其他通知方式,Bark对推送内容长度有限制 ⚠⚠⚠⚠⚠⚠⚠⚠⚠\n`)
console.log(`⚠️⚠️⚠️⚠️目前Bark APP推送通知消息失败的,请换用其他通知方式,Bark对推送内容长度有限制 ⚠️⚠️⚠️⚠️\n`)
await changeFile(content);
await execSign();
}
Expand All @@ -52,20 +54,20 @@ async function execSign() {
console.log(`\n开始执行脚本签到,请稍等`)
try {
if (notify.SCKEY || notify.BARK_PUSH || notify.DD_BOT_TOKEN || (notify.TG_BOT_TOKEN && notify.TG_USER_ID) || notify.IGOT_PUSH_KEY) {
await exec("node JD_DailyBonus.js >> result.txt");
await exec(`${process.execPath} ${JD_DailyBonusPath} >> ${resultPath}`);
} else {
// 如果没有提供通知推送,则打印日志
console.log('没有提供通知推送,则打印脚本执行日志')
await exec(`node JD_DailyBonus.js`, { stdio: "inherit" });
await exec(`${process.execPath} ${JD_DailyBonusPath}`, { stdio: "inherit" });
}
// await exec("node JD_DailyBonus.js", { stdio: "inherit" });
// console.log('执行完毕', new Date(new Date().getTime() + 8 * 60 * 60 * 1000).toLocaleDateString())
//发送通知
if ($.isNode()) {
let notifyContent = "";
let BarkContent = '';
if (fs.existsSync(path)) {
notifyContent = await fs.readFileSync(path, "utf8");
if (fs.existsSync(resultPath)) {
notifyContent = await fs.readFileSync(resultPath, "utf8");
const barkContentStart = notifyContent.indexOf('【签到概览】')
const barkContentEnd = notifyContent.length;
if (process.env.JD_BEAN_SIGN_STOP_NOTIFY === 'true') return
Expand All @@ -90,7 +92,7 @@ async function execSign() {
}
//运行完成后,删除下载的文件
console.log('运行完成后,删除下载的文件\n')
await deleteFile(path);//删除result.txt
await deleteFile(resultPath);//删除result.txt
await deleteFile(JD_DailyBonusPath);//删除JD_DailyBonus.js
console.log(`*****************京东账号${$.index} ${$.nickName || $.UserName}京豆签到完成*******************\n`);
} catch (e) {
Expand All @@ -112,7 +114,12 @@ async function downFile () {
} else {
url = 'https://cdn.jsdelivr.net/gh/NobyDa/Script@master/JD-DailyBonus/JD_DailyBonus.js';
}
await download(url, './')
try {
await download(url, outPutUrl);
console.log('文件下载完毕');
} catch (e) {
console.log("文件下载异常:" + e);
}
}

async function changeFile (content) {
Expand Down Expand Up @@ -200,7 +207,17 @@ function downloadUrl(url = 'https://raw.githubusercontent.com/NobyDa/Script/mast
})
})
}

function requireConfig() {
return new Promise(resolve => {
const file = 'jd_bean_sign.js';
fs.access(file, fs.constants.W_OK, (err) => {
resultPath = err ? './tmp/result.txt' : resultPath;
JD_DailyBonusPath = err ? './tmp/JD_DailyBonus.js' : JD_DailyBonusPath;
outPutUrl = err ? './tmp/' : outPutUrl;
resolve()
});
})
}
function timeFormat(time) {
let date;
if (time) {
Expand Down

0 comments on commit dc5bf3b

Please sign in to comment.