-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c45d984
commit 5ecc0d1
Showing
4 changed files
with
82 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}) | ||
} | ||
|
||
} |