From c45d984410451382ab8892ed5297c5319cb39204 Mon Sep 17 00:00:00 2001 From: CaoMeiYouRen <996881204@qq.com> Date: Fri, 4 Oct 2024 22:25:41 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96=20ServerChanTurb?= =?UTF-8?q?o=20=E7=9A=84=E9=99=84=E5=8A=A0=E5=8F=82=E6=95=B0=E5=A3=B0?= =?UTF-8?q?=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/push/server-chan-turbo.ts | 52 +++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/src/push/server-chan-turbo.ts b/src/push/server-chan-turbo.ts index 8336ae6..028b362 100644 --- a/src/push/server-chan-turbo.ts +++ b/src/push/server-chan-turbo.ts @@ -5,6 +5,43 @@ import { ajax } from '@/utils/ajax' const Debugger = debug('push:server-chan-turbo') +export type ChannelValue = 98 | 66 | 1 | 2 | 3 | 8 | 0 | 88 | 18 | 9 + +export type Channel = `${ChannelValue}` | `${ChannelValue}|${ChannelValue}` + +/** + * 附加参数 + */ +export type ServerChanTurboOptions = { + /** + * 消息卡片内容,选填。最大长度 64。如果不指定,将自动从 desp 中截取生成。 + */ + short?: string + /** + * 是否隐藏调用 IP,选填。如果不指定,则显示;为 1 则隐藏。 + */ + noip?: '1' | 1 | true + /** + * 动态指定本次推送使用的消息通道,选填。如不指定,则使用网站上的消息通道页面设置的通道。支持最多两个通道,多个通道值用竖线 "|" 隔开。 + * 通道对应的值如下: + * 官方Android版·β=98 + * 企业微信应用消息=66 + * 企业微信群机器人=1 + * 钉钉群机器人=2 + * 飞书群机器人=3 + * Bark iOS=8 + * 测试号=0 + * 自定义=88 + * PushDeer=18 + * 方糖服务号=9 + */ + channel?: Channel + /** + * 消息抄送的 openid,选填。只支持测试号和企业微信应用消息通道。多个 openid 用 "," 隔开。企业微信应用消息通道的 openid 参数,内容为接收人在企业微信中的 UID,多个人请 "|" 隔开。 + */ + openid?: string +} + /** * 文档 https://sct.ftqq.com/ * @@ -43,18 +80,23 @@ export class ServerChanTurbo implements Send { * @param text 消息的标题 * @param desp 消息的内容,支持 Markdown */ - async send(text: string, desp: string = ''): Promise> { + async send(text: string, desp: string = '', options: ServerChanTurboOptions = {}): Promise> { Debugger('text: "%s", desp: "%s"', text, desp) + if (options.noip === 1 || options.noip === true) { + options.noip = '1' + } + const data = { + text, + desp, + ...options, + } return ajax({ url: `https://sctapi.ftqq.com/${this.SCTKEY}.send`, method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', }, - data: { - text, - desp, - }, + data, }) } }