From f8706815d6109a262029e7b26a28de6b50c28835 Mon Sep 17 00:00:00 2001 From: Easy Date: Tue, 22 Oct 2024 15:41:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96sendkey=E7=9A=84=E5=85=BC?= =?UTF-8?q?=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/services/notify.ts | 6 ++++-- sample/notify.js | 10 ++++++---- sample/notify.py | 8 ++++++-- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/back/services/notify.ts b/back/services/notify.ts index b018c0b5..a229d305 100644 --- a/back/services/notify.ts +++ b/back/services/notify.ts @@ -151,9 +151,11 @@ export default class NotificationService { private async serverChan() { const { serverChanKey } = this.params; - const url = serverChanKey.startsWith('sctp') - ? `https://${serverChanKey}.push.ft07.com/send` + const matchResult = serverChanKey.match(/^sctp(\d+)t/i); + const url = matchResult + ? `https://${matchResult[1]}.push.ft07.com/send/${serverChanKey}.send` : `https://sctapi.ftqq.com/${serverChanKey}.send`; + try { const res: any = await got .post(url, { diff --git a/sample/notify.js b/sample/notify.js index f5c77cd1..edae3c29 100644 --- a/sample/notify.js +++ b/sample/notify.js @@ -224,11 +224,13 @@ function serverNotify(text, desp) { if (PUSH_KEY) { // 微信server酱推送通知一个\n不会换行,需要两个\n才能换行,故做此替换 desp = desp.replace(/[\n\r]/g, '\n\n'); + + const matchResult = PUSH_KEY.match(/^sctp(\d+)t/i); const options = { - url: PUSH_KEY.startsWith('sctp') - ? `https://${PUSH_KEY}.push.ft07.com/send` - : `https://sctapi.ftqq.com/${PUSH_KEY}.send`, - body: `text=${text}&desp=${desp}`, + url: matchResult + ? `https://${matchResult[1]}.push.ft07.com/send/${PUSH_KEY}.send` + : `https://sctapi.ftqq.com/${PUSH_KEY}.send`, + body: `text=${encodeURIComponent(text)}&desp=${encodeURIComponent(desp)}`, headers: { 'Content-Type': 'application/x-www-form-urlencoded', }, diff --git a/sample/notify.py b/sample/notify.py index 4f4ceb3c..ee578d96 100644 --- a/sample/notify.py +++ b/sample/notify.py @@ -298,10 +298,14 @@ def serverJ(title: str, content: str) -> None: print("serverJ 服务启动") data = {"text": title, "desp": content.replace("\n", "\n\n")} - if push_config.get("PUSH_KEY").startswith("sctp"): - url = f'https://{push_config.get("PUSH_KEY")}.push.ft07.com/send' + + match = re.match(r'sctp(\d+)t', push_config.get("PUSH_KEY")) + if match: + num = match.group(1) + url = f'https://{num}.push.ft07.com/send/{push_config.get("PUSH_KEY")}.send' else: url = f'https://sctapi.ftqq.com/{push_config.get("PUSH_KEY")}.send' + response = requests.post(url, data=data).json() if response.get("errno") == 0 or response.get("code") == 0: