1 Star 0 Fork 4

walker168/JD_Sign_Action

forked from Firlsy/JD_Sign_Action 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
jd_sign.js 2.80 KB
一键复制 编辑 原始数据 按行查看 历史
ZhiHua 提交于 2020-08-31 09:33 . update
// version v0.0.1
// create by zhihua
// detail url: https://github.com/ruicky/jd_sign_bot
const exec = require('child_process').execSync
const fs = require('fs')
const rp = require('request-promise')
const download = require('download')
// 京东cookie
const cookie = process.env.JD_COOKIE
// Server酱SCKEY
const push_key = process.env.PUSH_KEY
// 京东脚本文件
const js_url = 'https://raw.githubusercontent.com/NobyDa/Script/master/JD-DailyBonus/JD_DailyBonus.js'
// 下载脚本路劲
const js_path = './JD_DailyBonus.js'
// 脚本执行输出路劲
const result_path = './result.txt'
// 错误信息输出路劲
const error_path = './error.txt'
Date.prototype.Format = function (fmt) {
var o = {
'M+': this.getMonth() + 1,
'd+': this.getDate(),
'H+': this.getHours(),
'm+': this.getMinutes(),
's+': this.getSeconds(),
'S+': this.getMilliseconds()
};
if (/(y+)/.test(fmt)) {
fmt = fmt.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
}
for (var k in o) {
if (new RegExp('(' + k + ')').test(fmt)) {
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (('00' + o[k]).substr(String(o[k]).length)));
}
}
return fmt;
};
function setupCookie() {
var js_content = fs.readFileSync(js_path, 'utf8')
js_content = js_content.replace(/var Key = ''/, `var Key = '${cookie}'`)
fs.writeFileSync(js_path, js_content, 'utf8')
}
function sendNotificationIfNeed() {
if (!push_key) {
console.log('执行任务结束!'); return;
}
if (!fs.existsSync(result_path)) {
console.log('没有执行结果,任务中断!'); return;
}
let text = "京东签到_" + new Date().Format('yyyy.MM.dd');
let desp = fs.readFileSync(result_path, "utf8")
// 去除末尾的换行
let SCKEY = push_key.replace(/[\r\n]/g,"")
const options ={
uri: `https://sc.ftqq.com/${SCKEY}.send`,
form: { text, desp },
json: true,
method: 'POST'
}
rp.post(options).then(res=>{
const code = res['errno'];
if (code == 0) {
console.log("通知发送成功,任务结束!")
}
else {
console.log(res);
console.log("通知发送失败,任务中断!")
fs.writeFileSync(error_path, JSON.stringify(res), 'utf8')
}
}).catch((err)=>{
console.log("通知发送失败,任务中断!")
fs.writeFileSync(error_path, err, 'utf8')
})
}
function main() {
if (!cookie) {
console.log('请配置京东cookie!'); return;
}
// 1、下载脚本
download(js_url, './').then(res=>{
// 2、替换cookie
setupCookie()
// 3、执行脚本
exec(`node '${js_path}' >> '${result_path}'`);
// 4、发送推送
sendNotificationIfNeed()
}).catch((err)=>{
console.log('脚本文件下载失败,任务中断!');
fs.writeFileSync(error_path, err, 'utf8')
})
}
main()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/walker168/JD_Sign_Action.git
git@gitee.com:walker168/JD_Sign_Action.git
walker168
JD_Sign_Action
JD_Sign_Action
master

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385