Skip to content

Commit

Permalink
feat: 新增 Server 酱³ 支持
Browse files Browse the repository at this point in the history
  • Loading branch information
CaoMeiYouRen committed Oct 4, 2024
1 parent c45d984 commit 5ecc0d1
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 6 deletions.
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</a>
</p>

> Push All In One!支持 Server 酱、自定义邮件、钉钉机器人、企业微信机器人、企业微信应用、pushplus、iGot 、Qmsg、息知、PushDeer、Discord、OneBot、Telegram 等多种推送方式。
> Push All In One!支持 Server 酱(以及 Server 酱³)、自定义邮件、钉钉机器人、企业微信机器人、企业微信应用、pushplus、iGot 、Qmsg、息知、PushDeer、Discord、OneBot、Telegram 等多种推送方式。
>
> 温馨提示:出于安全考虑, **所有** 推送方式请在 **服务端** 使用!请勿在 **客户端(网页端)** 使用!网页端使用还将额外产生跨域问题。
Expand Down Expand Up @@ -52,13 +52,19 @@ npm i push-all-in-one -S
## 👨‍💻 使用

```ts
import { ServerChanTurbo, CustomEmail, Dingtalk, WechatRobot, WechatApp, PushPlus, IGot, Qmsg, XiZhi, PushDeer, Discord, OneBot, Telegram } from 'push-all-in-one'
import { ServerChanTurbo, ServerChanV3, CustomEmail, Dingtalk, WechatRobot, WechatApp, PushPlus, IGot, Qmsg, XiZhi, PushDeer, Discord, OneBot, Telegram } from 'push-all-in-one'

// Server酱。官方文档:https://sct.ftqq.com/r/13172
// Server酱·Turbo。官方文档:https://sct.ftqq.com/r/13172
const SCTKEY = 'SCTxxxxxxxxxxxxxxxxxxx'
const serverChanTurbo = new ServerChanTurbo(SCTKEY)
serverChanTurbo.send('你好', '你好,我很可爱')

// 【推荐】Server酱³
// Server酱3。官方文档:https://sc3.ft07.com/doc
const sendkey = 'sctpXXXXXXXXXXXXXXXXXXXXXXXX'
const serverChanV3 = new ServerChanV3(sendkey)
serverChanV3.send('你好', '你好,我很可爱 - 来自 Server酱³')

// 【推荐】自定义邮件,基于 nodemailer 实现,官方文档: https://github.com/nodemailer/nodemailer
const customEmail = new CustomEmail({
EMAIL_TYPE: 'text',
Expand Down Expand Up @@ -115,7 +121,7 @@ const XI_ZHI_KEY = 'xxxxxxxxxxxxx'
const xiZhi = new XiZhi(XI_ZHI_KEY)
xiZhi.send('你好', '你好,我很可爱 - XiZhi')

// 【推荐】PushDeer 推送,官方文档:https://github.com/easychen/pushdeer
// PushDeer 推送,官方文档:https://github.com/easychen/pushdeer
const PUSH_DEER_PUSH_KEY = 'xxxxxxxxxx'
const pushDeer = new PushDeer(PUSH_DEER_PUSH_KEY)
pushDeer.send('你好', '你好,我很可爱 - PushDeer', 'markdown')
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export * from './push/push-deer'
export * from './push/push-plus'
export * from './push/qmsg'
export * from './push/server-chan-turbo'
export * from './push/server-chan-v3'
export * from './push/telegram'
export * from './push/wechat-app'
export * from './push/wechat-robot'
Expand Down
5 changes: 3 additions & 2 deletions src/push/server-chan-turbo.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AxiosResponse } from 'axios'
import debug from 'debug'
import { Send } from '../interfaces/send'
import { Send } from '@/interfaces/send'
import { ajax } from '@/utils/ajax'

const Debugger = debug('push:server-chan-turbo')
Expand Down Expand Up @@ -43,6 +43,7 @@ export type ServerChanTurboOptions = {
}

/**
* Server 酱·Turbo
* 文档 https://sct.ftqq.com/
*
* @author CaoMeiYouRen
Expand Down Expand Up @@ -81,7 +82,7 @@ export class ServerChanTurbo implements Send {
* @param desp 消息的内容,支持 Markdown
*/
async send(text: string, desp: string = '', options: ServerChanTurboOptions = {}): Promise<AxiosResponse<any>> {
Debugger('text: "%s", desp: "%s"', text, desp)
Debugger('text: "%s", desp: "%s", options: %O', text, desp, options)
if (options.noip === 1 || options.noip === true) {
options.noip = '1'
}
Expand Down
68 changes: 68 additions & 0 deletions src/push/server-chan-v3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { AxiosResponse } from 'axios'
import debug from 'debug'
import { Send } from '@/interfaces/send'
import { ajax } from '@/utils/ajax'

const Debugger = debug('push:server-chan-v3')

/**
* 附加参数
*/
export type ServerChanV3Options = {
tags?: string | string[] // 标签列表,多个标签使用竖线分隔;也可以用数组格式,数组格式下不要加竖线
short?: string // 推送消息的简短描述,用于指定消息卡片的内容部分,尤其是在推送markdown的时候
}

/**
* Server酱³
* 文档:https://sc3.ft07.com/doc
* @author CaoMeiYouRen
* @date 2024-10-04
* @export
* @class ServerChanV3
*/
export class ServerChanV3 implements Send {

/**
* 请前往 https://sc3.ft07.com/sendkey 领取
*
* @author CaoMeiYouRen
* @date 2024-10-04
* @private
*/
private sendkey: string

/**
* @author CaoMeiYouRen
* @date 2024-10-04
* @param sendkey 请前往 https://sc3.ft07.com/sendkey 领取
*/
constructor(sendkey: string) {
this.sendkey = sendkey
Debugger('set sendkey: "%s"', sendkey)
if (!this.sendkey) {
throw new Error('sendkey 是必须的!')
}
}

async send(text: string, desp: string = '', options: ServerChanV3Options = {}): Promise<any> {
Debugger('text: "%s", desp: "%s", options: %O', text, desp, options)
if (Array.isArray(options.tags)) {
options.tags = options.tags.join('|')
}
const data = {
text,
desp,
...options,
}
return ajax({
url: `https://${this.sendkey}.push.ft07.com/send`,
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
data,
})
}

}

0 comments on commit 5ecc0d1

Please sign in to comment.