From dc5bf3b822df3f3e8b2a5683d423e6e27d975b6c Mon Sep 17 00:00:00 2001 From: lxk0301 <778732665@qq.com> Date: Tue, 17 Nov 2020 10:22:27 +0800 Subject: [PATCH] =?UTF-8?q?jd=5Fbean=5Fsign.js=E4=BA=AC=E8=B1=86=E7=AD=BE?= =?UTF-8?q?=E5=88=B0=E5=85=BC=E5=AE=B9=E8=85=BE=E8=AE=AF=E4=BA=91=E5=87=BD?= =?UTF-8?q?=E6=95=B0=EF=BC=8C=E6=84=9F=E8=B0=A2github@ykrank=E6=8F=90?= =?UTF-8?q?=E4=BE=9B=E7=9A=84=E5=B8=AE=E5=8A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jd_bean_sign.js | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/jd_bean_sign.js b/jd_bean_sign.js index a013c92..f972afd 100644 --- a/jd_bean_sign.js +++ b/jd_bean_sign.js @@ -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 @@ -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()) { @@ -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) { @@ -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(); } @@ -52,11 +54,11 @@ 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()) @@ -64,8 +66,8 @@ async function execSign() { 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 @@ -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) { @@ -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) { @@ -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) {