85 lines
2.5 KiB
JavaScript
85 lines
2.5 KiB
JavaScript
const Init = require("./init");
|
||
const nodemailer = require("nodemailer");
|
||
const Times = require("../public/times");
|
||
|
||
const conf = {
|
||
create_config: {
|
||
service: "qq",
|
||
secureConnection: true,
|
||
port: 465,
|
||
auth: {
|
||
user: "393768033@qq.com",
|
||
// pass: "hyaefuvaiudcbihj",
|
||
pass:"anuflpiziamwcaia",
|
||
},
|
||
},
|
||
symbol:["nexa", "rxd", "dgbs", "dgbq", "dgbo", "grs", "mona", "enx"],
|
||
receiver: "709387953@qq.com, liarsars@gmail.com"
|
||
};
|
||
|
||
class Notice extends Init {
|
||
constructor(coin) {
|
||
super(coin, "notice");
|
||
this.conf = conf;
|
||
this.transporter = nodemailer.createTransport(conf.create_config);
|
||
}
|
||
|
||
construct_mail(receiver, subject, text, html) {
|
||
return {
|
||
from: this.transporter.options.auth.user,
|
||
to: receiver,
|
||
subject: subject,
|
||
text: text,
|
||
html: html
|
||
};
|
||
}
|
||
|
||
async send_mail(mailOptions) {
|
||
if (!mailOptions.to) {
|
||
throw new Error("未指定收件人");
|
||
}
|
||
try {
|
||
const info = await this.transporter.sendMail(mailOptions);
|
||
console.log(`${Date.now()} 检测到未转账信息!邮件ID: ${info.messageId}`);
|
||
} catch (err) {
|
||
console.error("邮件发送失败:", err);
|
||
}
|
||
}
|
||
|
||
async query_walletout(date) {
|
||
try {
|
||
const sql = `SELECT * FROM wallet_outv2 WHERE DATE(date) = ?;`;
|
||
const data = await this.distribution.exec(sql, [date]);
|
||
return data.length > 0 ? data : false;
|
||
} catch (err) {
|
||
throw err;
|
||
}
|
||
}
|
||
|
||
async main() {
|
||
try {
|
||
const date = Times.times()[2];
|
||
const data = await this.query_walletout(date);
|
||
|
||
if (!data) return;
|
||
|
||
const symbol = new Set(data.map(item => item.coin));
|
||
|
||
const transfer_err_coins = (this.conf.symbol || []).filter(item => !symbol.has(item));
|
||
|
||
if (transfer_err_coins.length === 0) return;
|
||
|
||
const subject = `今日有未转账币种`;
|
||
const text = `今日有未转账币种`;
|
||
const html = `今日未转账币种:${transfer_err_coins.join(", ")}<h1>测试数据</h1>`;
|
||
|
||
const mailOptions = this.construct_mail(this.conf.receiver, subject, text, html);
|
||
await this.send_mail(mailOptions);
|
||
return
|
||
} catch (err) {
|
||
console.error("主任务执行错误:", err);
|
||
}
|
||
}
|
||
}
|
||
|
||
module.exports = Notice |