jd_bean_sign.js京豆签到兼容腾讯云函数,感谢github@ykrank提供的帮助
This commit is contained in:
@ -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) {
|
||||
|
Reference in New Issue
Block a user