From b92b9c2ad4b720067ba9b50180f6b48ef69ed39c Mon Sep 17 00:00:00 2001 From: Ahaochan <844394093@qq.com> Date: Tue, 7 Feb 2023 11:19:44 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sample/notify.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ sample/notify.py | 22 ++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/sample/notify.js b/sample/notify.js index 6f3da33b..c3b9d069 100644 --- a/sample/notify.js +++ b/sample/notify.js @@ -125,6 +125,10 @@ let AIBOTK_NAME = ''; //FSKEY 飞书机器人的 FSKEY let FSKEY = ''; +// =======================================自定义通知设置区域======================================= +// 自定义通知 接收回调的URL +let CUSTOM_URL = ''; + // =======================================SMTP 邮件设置区域======================================= // SMTP_SERVER: 填写 SMTP 发送邮件服务器,形如 smtp.exmail.qq.com:465 // SMTP_SSL: 填写 SMTP 发送邮件服务器是否使用 SSL,内容应为 true 或 false @@ -278,6 +282,9 @@ if (process.env.SMTP_PASSWORD) { if (process.env.SMTP_NAME) { SMTP_NAME = process.env.SMTP_NAME; } +if (process.env.CUSTOM_URL) { + CUSTOM_URL = process.env.CUSTOM_URL; +} //==========================云端环境变量的判断与接收========================= /** @@ -316,6 +323,7 @@ async function sendNotify( aibotkNotify(text, desp), //智能微秘书 fsBotNotify(text, desp), //飞书机器人 smtpNotify(text, desp), //SMTP 邮件 + customNotify(text, desp), //自定义通知 ]); } @@ -1097,6 +1105,42 @@ function smtpNotify(text, desp) { }); } +function customNotify(text, desp) { + return new Promise((resolve) => { + const options = { + url: `${CUSTOM_URL}`, + json: { + title: text, + content: desp + }, + headers: { + 'Content-Type': 'application/json', + }, + timeout, + }; + if (CUSTOM_URL) { + $.post(options, (err, resp, data) => { + try { + if (err) { + console.log('自定义发送通知消息失败!!\n'); + console.log(err); + } else { + data = JSON.parse(data); + console.log('自定义发送通知消息成功🎉。\n'); + console.log(data); + } + } catch (e) { + $.logErr(e, resp); + } finally { + resolve(data); + } + }); + } else { + resolve(); + } + }); +} + module.exports = { sendNotify, BARK_PUSH, diff --git a/sample/notify.py b/sample/notify.py index 79ac9fb2..1099b109 100644 --- a/sample/notify.py +++ b/sample/notify.py @@ -96,6 +96,8 @@ push_config = { 'SMTP_EMAIL': '', # SMTP 收发件邮箱,通知将会由自己发给自己 'SMTP_PASSWORD': '', # SMTP 登录密码,也可能为特殊口令,视具体邮件服务商说明而定 'SMTP_NAME': '', # SMTP 收发件人姓名,可随意填写 + + 'CUSTOM_URL': '' # 自定义通知 接收回调的URL } notify_function = [] # fmt: on @@ -595,6 +597,24 @@ def smtp(title: str, content: str) -> None: except Exception as e: print(f'SMTP 邮件 推送失败!{e}') +def custom_notify(title: str, content: str) -> None: + """ + 通过 自定义通知 推送消息。 + """ + if not push_config.get("CUSTOM_URL"): + print("自定义通知 服务的 CUSTOM_URL 未设置!!\n取消推送") + return + print("自定义通知服务启动") + + url = f"{push_config.get('CUSTOM_URL')}" + headers = {"Content-Type": "application/json;charset=utf-8"} + data = {"title": f"{title}", "content": f"{content}"} + response = requests.post( + url=url, data=json.dumps(data), headers=headers, timeout=15 + ).json() + + print("自定义通知推送成功!") + print(response) def one() -> str: """ @@ -640,6 +660,8 @@ if push_config.get("AIBOTK_KEY") and push_config.get("AIBOTK_TYPE") and push_con notify_function.append(aibotk) if push_config.get("SMTP_SERVER") and push_config.get("SMTP_SSL") and push_config.get("SMTP_EMAIL") and push_config.get("SMTP_PASSWORD") and push_config.get("SMTP_NAME"): notify_function.append(smtp) +if push_config.get("CUSTOM_URL"): + notify_function.append(custom_notify) def send(title: str, content: str) -> None: