diff --git a/githubAction.md b/githubAction.md index 63f1d3f9..1635b8fb 100644 --- a/githubAction.md +++ b/githubAction.md @@ -90,6 +90,8 @@ | `DD_BOT_TOKEN` | 钉钉推送 | 非必须 | 钉钉推送[官方文档](https://ding-doc.dingtalk.com/doc#/serverapi2/qf2nxq) ,只需`https://oapi.dingtalk.com/robot/send?access_token=XXX` 等于符号后面的XXX, 注:如果钉钉推送只填写`DD_BOT_TOKEN`,那么安全设置需勾选`自定义关键词`,内容输入输入`账号`即可,其他安全设置不要勾选 | | `DD_BOT_SECRET` | 钉钉推送 | 非必须 | 密钥,机器人安全设置页面,加签一栏下面显示的SEC开头的字符串 , 注:填写了`DD_BOT_TOKEN`和`DD_BOT_SECRET`,钉钉机器人安全设置只需勾选`加签`即可,其他选项不要勾选,再不懂看 [这个图](icon/DD_bot.png) | | `IGOT_PUSH_KEY` | iGot推送 | 非必须 | iGot聚合推送,支持多方式推送,确保消息可达。 [参考文档](https://wahao.github.io/Bark-MP-helper ) | +| `QQ_SKEY` | 酷推(Cool Push)推送 | 非必须 | 推送所需的Skey,登录后获取Skey [参考文档](https://cp.xuthus.cc/) | +| `QQ_MODE` | 酷推(Cool Push)推送 | 非必须 | 推送方式(send或group或者wx,默认send) [参考文档](https://cp.xuthus.cc/) | | `PET_NOTIFY_CONTROL` | 东东萌宠推送开关 | 非必须 | 控制京东萌宠是否静默运行,`false`为否(发送推送通知消息),`true`为是(即:不发送推送通知消息) | | `FRUIT_NOTIFY_CONTROL` | 东东农场推送开关 | 非必须 | 控制京东农场是否静默运行,`false`为否(发送推送通知消息),`true`为是(即:不发送推送通知消息) | | `JD_JOY_REWARD_NOTIFY` | 宠汪汪兑换京豆推送开关 | 非必须 | 控制jd_joy_reward.js脚本是否静默运行,`false`为否(发送推送通知消息),`true`为是(即:不发送推送通知消息) diff --git a/jd_bean_sign.js b/jd_bean_sign.js index 10d51b3a..62b19a32 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-27 +更新时间:2020-12-21 从 github @ruicky改写而来 version v0.0.1 create by ruicky @@ -42,9 +42,9 @@ if ($.isNode()) { $.nickName = ''; await TotalBean(); console.log(`*****************开始京东账号${$.index} ${$.nickName || $.UserName}京豆签到*******************\n`); - console.log(`⚠️⚠️⚠️⚠️目前Bark APP推送通知消息对推送内容长度有限制,如使用此推送方式脚本会默认转换成简洁内容推送 ⚠️⚠️⚠️⚠️\n`) + console.log(`⚠️⚠️⚠️⚠️目前Bark APP推送通知消息对推送内容长度有限制,如推送通知中包含此推送方式脚本会默认转换成简洁内容推送 ⚠️⚠️⚠️⚠️\n`) await changeFile(content); - await execSign(); + await execSign(); } } })() @@ -53,15 +53,17 @@ if ($.isNode()) { 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(`${process.execPath} ${JD_DailyBonusPath} >> ${resultPath}`); - const notifyContent = await fs.readFileSync(resultPath, "utf8"); - console.log(`👇👇👇👇👇👇👇👇👇👇👇LOG记录👇👇👇👇👇👇👇👇👇👇👇\n${notifyContent}\n👆👆👆👆👆👆👆👆👆LOG记录👆👆👆👆👆👆👆👆👆👆👆`); - } else { - // 如果没有提供通知推送,则打印日志 - console.log('没有提供通知推送,则打印脚本执行日志') - await exec(`${process.execPath} ${JD_DailyBonusPath}`, { stdio: "inherit" }); - } + // if (notify.SCKEY || notify.BARK_PUSH || notify.DD_BOT_TOKEN || (notify.TG_BOT_TOKEN && notify.TG_USER_ID) || notify.IGOT_PUSH_KEY || notify.QQ_SKEY) { + // await exec(`${process.execPath} ${JD_DailyBonusPath} >> ${resultPath}`); + // const notifyContent = await fs.readFileSync(resultPath, "utf8"); + // console.log(`👇👇👇👇👇👇👇👇👇👇👇LOG记录👇👇👇👇👇👇👇👇👇👇👇\n${notifyContent}\n👆👆👆👆👆👆👆👆👆LOG记录👆👆👆👆👆👆👆👆👆👆👆`); + // } else { + // console.log('没有提供通知推送,则打印脚本执行日志') + // await exec(`${process.execPath} ${JD_DailyBonusPath}`, { stdio: "inherit" }); + // } + await exec(`${process.execPath} ${JD_DailyBonusPath} >> ${resultPath}`); + const notifyContent = await fs.readFileSync(resultPath, "utf8"); + console.log(`👇👇👇👇👇👇👇👇👇👇👇LOG记录👇👇👇👇👇👇👇👇👇👇👇\n${notifyContent}\n👆👆👆👆👆👆👆👆👆LOG记录👆👆👆👆👆👆👆👆👆👆👆`); // await exec("node JD_DailyBonus.js", { stdio: "inherit" }); // console.log('执行完毕', new Date(new Date().getTime() + 8 * 60 * 60 * 1000).toLocaleDateString()) //发送通知 diff --git a/sendNotify.js b/sendNotify.js index 703bafe3..6392824b 100644 --- a/sendNotify.js +++ b/sendNotify.js @@ -2,7 +2,7 @@ * @Author: lxk0301 https://github.com/lxk0301 * @Date: 2020-08-19 16:12:40 * @Last Modified by: lxk0301 - * @Last Modified time: 2020-12-20 13:52:54 + * @Last Modified time: 2020-12-21 13:52:54 */ const querystring = require("querystring"); const $ = new Env(); @@ -13,11 +13,11 @@ let SCKEY = ''; // =======================================QQ酷推通知设置区域=========================================== -//此处填你申请的SKEY. +//此处填你申请的SKEY(具体详见文档https://cp.xuthus.cc/) //注:此处设置github action用户填写到Settings-Secrets里面(Name输入QQ_SKEY) -let SKEY = ''; -//此处填写私聊或群组推送默认私聊(send或group) -let premode = 'send'; +let QQ_SKEY = ''; +//此处填写私聊或群组推送,默认私聊(send或group或者wx) +let QQ_MODE = 'send'; // =======================================Bark App通知设置区域=========================================== //此处填你BarkAPP的信息(IP/设备码,例如:https://api.day.app/XXXXXXXX) @@ -52,14 +52,15 @@ if (process.env.PUSH_KEY) { SCKEY = process.env.PUSH_KEY; } +//========================酷推(Cool Push)设置区域=============== if (process.env.QQ_SKEY) { - SKEY = process.env.QQ_SKEY; + QQ_SKEY = process.env.QQ_SKEY; +} + +if (process.env.QQ_MODE) { + QQ_MODE = process.env.QQ_MODE; } -if (process.env.QQ_mode) { - mode = process.env.QQ_mode; -} else { -mode = premode } if (process.env.BARK_PUSH) { if(process.env.BARK_PUSH.indexOf('https') > -1 || process.env.BARK_PUSH.indexOf('http') > -1) { @@ -98,12 +99,12 @@ if (process.env.IGOT_PUSH_KEY) { async function sendNotify(text, desp, params = {}) { //提供六种通知 await serverNotify(text, desp); - await CoolPush(text, desp); text = text.match(/.*?(?=\s?-)/g) ? text.match(/.*?(?=\s?-)/g)[0] : text; await BarkNotify(text, desp, params); await tgBotNotify(text, desp); await ddBotNotify(text, desp); await iGotNotify(text, desp, params); + await CoolPush(text, desp); } function serverNotify(text, desp, timeout = 2100) { @@ -122,14 +123,14 @@ function serverNotify(text, desp, timeout = 2100) { $.post(options, (err, resp, data) => { try { if (err) { - console.log('\n发送通知调用API失败!!\n') + console.log('发送通知调用API失败!!\n') console.log(err); } else { data = JSON.parse(data); if (data.errno === 0) { - console.log('\nserver酱发送通知消息成功\n') + console.log('server酱发送通知消息成功\n') } else if (data.errno === 1024) { - console.log('\nPUSH_KEY 错误\n') + console.log('PUSH_KEY 错误\n') } else { console.log(`server酱发送通知消息异常\n${JSON.stringify(data)}`) } @@ -142,7 +143,7 @@ function serverNotify(text, desp, timeout = 2100) { }) }, timeout) } else { - console.log('\n您未提供server酱的SCKEY,取消微信推送消息通知\n'); + console.log('您未提供server酱的SCKEY,取消微信推送消息通知\n'); resolve() } }) @@ -150,24 +151,25 @@ function serverNotify(text, desp, timeout = 2100) { function CoolPush(text, desp) { return new Promise(resolve => { - if (SKEY) { + if (QQ_SKEY) { const options = { - url: `https://push.xuthus.cc/${mode}/${SKEY}?c=${text}\n\n${desp}`, + url: `https://push.xuthus.cc/${QQ_MODE}/${QQ_SKEY}`, + body: `${text}\n\n${desp}`, headers: { - 'Content-Type': 'application/x-www-form-urlencoded' + 'Content-Type': 'application/json' } } $.post(options, (err, resp, data) => { try { if (err) { - console.log('\n发送通知调用API失败!!\n') + console.log('发送通知调用API失败!!\n') console.log(err); } else { data = JSON.parse(data); if (data.code === 200) { - console.log('\n酷推发送通知消息成功\n') + console.log('酷推发送通知消息成功\n') } else if (data.code === 400) { - console.log('\nPUSH_SKEY 错误\n') + console.log(`推送失败:${data.msg}\n`) } } } catch (e) { @@ -177,7 +179,7 @@ function CoolPush(text, desp) { } }) } else { - console.log('\n您未提供酷推的SKEY,取消QQ推送消息通知\n'); + console.log('您未提供酷推的SKEY,取消QQ推送消息通知\n'); resolve() } }) @@ -195,14 +197,14 @@ function BarkNotify(text, desp, params={}) { $.get(options, (err, resp, data) => { try { if (err) { - console.log('\nBark APP发送通知调用API失败!!\n') + console.log('Bark APP发送通知调用API失败!!\n') console.log(err); } else { data = JSON.parse(data); if (data.code === 200) { - console.log('\nBark APP发送通知消息成功\n') + console.log('Bark APP发送通知消息成功\n') } else { - console.log(`\n${data.message}\n`); + console.log(`${data.message}\n`); } } } catch (e) { @@ -212,7 +214,7 @@ function BarkNotify(text, desp, params={}) { } }) } else { - console.log('\n您未提供Bark的APP推送BARK_PUSH,取消Bark推送消息通知\n'); + console.log('您未提供Bark的APP推送BARK_PUSH,取消Bark推送消息通知\n'); resolve() } }) @@ -243,16 +245,16 @@ function tgBotNotify(text, desp) { $.post(options, (err, resp, data) => { try { if (err) { - console.log('\ntelegram发送通知消息失败!!\n') + console.log('telegram发送通知消息失败!!\n') console.log(err); } else { data = JSON.parse(data); if (data.ok) { - console.log('\nTelegram发送通知消息完成。\n') + console.log('Telegram发送通知消息完成。\n') } else if (data.error_code === 400) { - console.log('\n请主动给bot发送一条消息并检查接收用户ID是否正确。\n') + console.log('请主动给bot发送一条消息并检查接收用户ID是否正确。\n') } else if (data.error_code === 401){ - console.log('\nTelegram bot token 填写错误。\n') + console.log('Telegram bot token 填写错误。\n') } } } catch (e) { @@ -262,7 +264,7 @@ function tgBotNotify(text, desp) { } }) } else { - console.log('\n您未提供telegram机器人推送所需的TG_BOT_TOKEN和TG_USER_ID,取消telegram推送消息通知\n'); + console.log('您未提供telegram机器人推送所需的TG_BOT_TOKEN和TG_USER_ID,取消telegram推送消息通知\n'); resolve() } }) @@ -291,14 +293,14 @@ function ddBotNotify(text, desp) { $.post(options, (err, resp, data) => { try { if (err) { - console.log('\n钉钉发送通知消息失败!!\n') + console.log('钉钉发送通知消息失败!!\n') console.log(err); } else { data = JSON.parse(data); if (data.errcode === 0) { - console.log('\n钉钉发送通知消息完成。\n') + console.log('钉钉发送通知消息完成。\n') } else { - console.log(`\n${data.errmsg}\n`) + console.log(`${data.errmsg}\n`) } } } catch (e) { @@ -311,14 +313,14 @@ function ddBotNotify(text, desp) { $.post(options, (err, resp, data) => { try { if (err) { - console.log('\n钉钉发送通知消息失败!!\n') + console.log('钉钉发送通知消息失败!!\n') console.log(err); } else { data = JSON.parse(data); if (data.errcode === 0) { - console.log('\n钉钉发送通知消息完成。\n') + console.log('钉钉发送通知消息完成。\n') } else { - console.log(`\n${data.errmsg}\n`) + console.log(`${data.errmsg}\n`) } } } catch (e) { @@ -328,7 +330,7 @@ function ddBotNotify(text, desp) { } }) } else { - console.log('\n您未提供钉钉机器人推送所需的DD_BOT_TOKEN或者DD_BOT_SECRET,取消钉钉推送消息通知\n'); + console.log('您未提供钉钉机器人推送所需的DD_BOT_TOKEN或者DD_BOT_SECRET,取消钉钉推送消息通知\n'); resolve() } }) @@ -340,7 +342,7 @@ function iGotNotify(text, desp, params={}){ // 校验传入的IGOT_PUSH_KEY是否有效 const IGOT_PUSH_KEY_REGX = new RegExp("^[a-zA-Z0-9]{24}$") if(!IGOT_PUSH_KEY_REGX.test(IGOT_PUSH_KEY)) { - console.log('\n您所提供的IGOT_PUSH_KEY无效\n') + console.log('您所提供的IGOT_PUSH_KEY无效\n') resolve() return } @@ -354,14 +356,14 @@ function iGotNotify(text, desp, params={}){ $.post(options, (err, resp, data) => { try { if (err) { - console.log('\n发送通知调用API失败!!\n') + console.log('发送通知调用API失败!!\n') console.log(err); } else { if(typeof data === 'string') data = JSON.parse(data); if (data.ret === 0) { - console.log('\niGot发送通知消息成功\n') + console.log('iGot发送通知消息成功\n') } else { - console.log(`\niGot发送通知消息失败:${data.errMsg}\n`) + console.log(`iGot发送通知消息失败:${data.errMsg}\n`) } } } catch (e) { @@ -371,21 +373,14 @@ function iGotNotify(text, desp, params={}){ } }) } else { - console.log('\n您未提供iGot的推送IGOT_PUSH_KEY,取消iGot推送消息通知\n'); + console.log('您未提供iGot的推送IGOT_PUSH_KEY,取消iGot推送消息通知\n'); resolve() } }) } module.exports = { - sendNotify, - SCKEY, - SKEY, - BARK_PUSH, - TG_BOT_TOKEN, - TG_USER_ID, - DD_BOT_TOKEN, - IGOT_PUSH_KEY -}//这里导出SCKEY,BARK_PUSH等通知参数是jd_bean_sign.js处需要 + sendNotify +} // prettier-ignore function Env(t,s){return new class{constructor(t,s){this.name=t,this.data=null,this.dataFile="box.dat",this.logs=[],this.logSeparator="\n",this.startTime=(new Date).getTime(),Object.assign(this,s),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $httpClient&&"undefined"==typeof $loon}isLoon(){return"undefined"!=typeof $loon}getScript(t){return new Promise(s=>{$.get({url:t},(t,e,i)=>s(i))})}runScript(t,s){return new Promise(e=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let o=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");o=o?1*o:20,o=s&&s.timeout?s.timeout:o;const[h,a]=i.split("@"),r={url:`http://${a}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:o},headers:{"X-Key":h,Accept:"*/*"}};$.post(r,(t,s,i)=>e(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),s=this.path.resolve(process.cwd(),this.dataFile),e=this.fs.existsSync(t),i=!e&&this.fs.existsSync(s);if(!e&&!i)return{};{const i=e?t:s;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),s=this.path.resolve(process.cwd(),this.dataFile),e=this.fs.existsSync(t),i=!e&&this.fs.existsSync(s),o=JSON.stringify(this.data);e?this.fs.writeFileSync(t,o):i?this.fs.writeFileSync(s,o):this.fs.writeFileSync(t,o)}}lodash_get(t,s,e){const i=s.replace(/\[(\d+)\]/g,".$1").split(".");let o=t;for(const t of i)if(o=Object(o)[t],void 0===o)return e;return o}lodash_set(t,s,e){return Object(t)!==t?t:(Array.isArray(s)||(s=s.toString().match(/[^.[\]]+/g)||[]),s.slice(0,-1).reduce((t,e,i)=>Object(t[e])===t[e]?t[e]:t[e]=Math.abs(s[i+1])>>0==+s[i+1]?[]:{},t)[s[s.length-1]]=e,t)}getdata(t){let s=this.getval(t);if(/^@/.test(t)){const[,e,i]=/^@(.*?)\.(.*?)$/.exec(t),o=e?this.getval(e):"";if(o)try{const t=JSON.parse(o);s=t?this.lodash_get(t,i,""):s}catch(t){s=""}}return s}setdata(t,s){let e=!1;if(/^@/.test(s)){const[,i,o]=/^@(.*?)\.(.*?)$/.exec(s),h=this.getval(i),a=i?"null"===h?null:h||"{}":"{}";try{const s=JSON.parse(a);this.lodash_set(s,o,t),e=this.setval(JSON.stringify(s),i)}catch(s){const h={};this.lodash_set(h,o,t),e=this.setval(JSON.stringify(h),i)}}else e=$.setval(t,s);return e}getval(t){return this.isSurge()||this.isLoon()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,s){return this.isSurge()||this.isLoon()?$persistentStore.write(t,s):this.isQuanX()?$prefs.setValueForKey(t,s):this.isNode()?(this.data=this.loaddata(),this.data[s]=t,this.writedata(),!0):this.data&&this.data[s]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,s=(()=>{})){t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isLoon()?$httpClient.get(t,(t,e,i)=>{!t&&e&&(e.body=i,e.statusCode=e.status),s(t,e,i)}):this.isQuanX()?$task.fetch(t).then(t=>{const{statusCode:e,statusCode:i,headers:o,body:h}=t;s(null,{status:e,statusCode:i,headers:o,body:h},h)},t=>s(t)):this.isNode()&&(this.initGotEnv(t),this.got(t).on("redirect",(t,s)=>{try{const e=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();this.ckjar.setCookieSync(e,null),s.cookieJar=this.ckjar}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:e,statusCode:i,headers:o,body:h}=t;s(null,{status:e,statusCode:i,headers:o,body:h},h)},t=>s(t)))}post(t,s=(()=>{})){if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),delete t.headers["Content-Length"],this.isSurge()||this.isLoon())$httpClient.post(t,(t,e,i)=>{!t&&e&&(e.body=i,e.statusCode=e.status),s(t,e,i)});else if(this.isQuanX())t.method="POST",$task.fetch(t).then(t=>{const{statusCode:e,statusCode:i,headers:o,body:h}=t;s(null,{status:e,statusCode:i,headers:o,body:h},h)},t=>s(t));else if(this.isNode()){this.initGotEnv(t);const{url:e,...i}=t;this.got.post(e,i).then(t=>{const{statusCode:e,statusCode:i,headers:o,body:h}=t;s(null,{status:e,statusCode:i,headers:o,body:h},h)},t=>s(t))}}time(t){let s={"M+":(new Date).getMonth()+1,"d+":(new Date).getDate(),"H+":(new Date).getHours(),"m+":(new Date).getMinutes(),"s+":(new Date).getSeconds(),"q+":Math.floor(((new Date).getMonth()+3)/3),S:(new Date).getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,((new Date).getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in s)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?s[e]:("00"+s[e]).substr((""+s[e]).length)));return t}msg(s=t,e="",i="",o){const h=t=>!t||!this.isLoon()&&this.isSurge()?t:"string"==typeof t?this.isLoon()?t:this.isQuanX()?{"open-url":t}:void 0:"object"==typeof t&&(t["open-url"]||t["media-url"])?this.isLoon()?t["open-url"]:this.isQuanX()?t:void 0:void 0;$.isMute||(this.isSurge()||this.isLoon()?$notification.post(s,e,i,h(o)):this.isQuanX()&&$notify(s,e,i,h(o))),this.logs.push("","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="),this.logs.push(s),e&&this.logs.push(e),i&&this.logs.push(i)}log(...t){t.length>0?this.logs=[...this.logs,...t]:console.log(this.logs.join(this.logSeparator))}logErr(t,s){const e=!this.isSurge()&&!this.isQuanX()&&!this.isLoon();e?$.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):$.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t)}wait(t){return new Promise(s=>setTimeout(s,t))}done(t={}){const s=(new Date).getTime(),e=(s-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${e} \u79d2`),this.log(),(this.isSurge()||this.isQuanX()||this.isLoon())&&$done(t)}}(t,s)}