-
Notifications
You must be signed in to change notification settings - Fork 335
/
app.js
66 lines (58 loc) · 1.71 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// version v0.0.1
// create by ruicky
// 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')
// 公共变量
const KEY = process.env.JD_COOKIE
const serverJ = process.env.PUSH_KEY
async function downFile () {
// const url = 'https://cdn.jsdelivr.net/gh/NobyDa/Script@master/JD-DailyBonus/JD_DailyBonus.js'
const url = 'https://raw.githubusercontent.com/NobyDa/Script/master/JD-DailyBonus/JD_DailyBonus.js'
await download(url, './')
}
async function changeFiele () {
let content = await fs.readFileSync('./JD_DailyBonus.js', 'utf8')
content = content.replace(/var Key = ''/, `var Key = '${KEY}'`)
await fs.writeFileSync( './JD_DailyBonus.js', content, 'utf8')
}
async function sendNotify (text,desp) {
const options ={
uri: `https://sc.ftqq.com/${serverJ}.send`,
form: { text, desp },
json: true,
method: 'POST'
}
await rp.post(options).then(res=>{
console.log(res)
}).catch((err)=>{
console.log(err)
})
}
async function start() {
if (!KEY) {
console.log('请填写 key 后在继续')
return
}
// 下载最新代码
await downFile();
console.log('下载代码完毕')
// 替换变量
await changeFiele();
console.log('替换变量完毕')
// 执行
await exec("node JD_DailyBonus.js >> result.txt");
console.log('执行完毕')
if (serverJ) {
const path = "./result.txt";
let content = "";
if (fs.existsSync(path)) {
content = fs.readFileSync(path, "utf8");
}
await sendNotify("京东签到-" + new Date().toLocaleDateString(), content);
console.log('发送结果完毕')
}
}
start()