diff --git a/README.md b/README.md index efaca89..f416f3d 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ npm i push-all-in-one -S ## 使用 ```ts -import { ServerChanTurbo, CoolPush, Dingtalk, Email, WechatRobot, WechatApp, PushPlus, IGot, Qmsg } from 'push-all-in-one' +import { ServerChanTurbo, CoolPush, Dingtalk, Email, WechatRobot, WechatApp, PushPlus, IGot, Qmsg, XiZhi } from 'push-all-in-one' // Server酱。官方文档:https://sct.ftqq.com/ const SCTKEY = 'SCTxxxxxxxxxxxxxxxxxxx' @@ -106,6 +106,11 @@ const QMSG_KEY = 'xxxxxxxxxxxx' const qmsg = new Qmsg(QMSG_KEY) qmsg.send('你好,我很可爱 - Qmsg', '12345,12346', 'send') // msg:要推送的消息内容;qq:指定要接收消息的QQ号或者QQ群,多个以英文逗号分割,例如:12345,12346 + +// 息知 推送,官方文档:https://xz.qqoq.net/#/index +const XI_ZHI_KEY = 'xxxxxxxxxxxxx' +const xiZhi = new XiZhi(XI_ZHI_KEY) +xiZhi.send('你好', '你好,我很可爱 - XiZhi') ``` ## 开发 diff --git a/src/index.ts b/src/index.ts index 95c4281..3194cd0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,3 +7,5 @@ export * from './push/qmsg' export * from './push/server-chan-turbo' export * from './push/wechat-app' export * from './push/wechat-robot' +export * from './push/xi-zhi' + diff --git a/src/push/qmsg.ts b/src/push/qmsg.ts index 7bdbb08..35dc96a 100644 --- a/src/push/qmsg.ts +++ b/src/push/qmsg.ts @@ -30,7 +30,8 @@ export class Qmsg implements Send { } } - async send(msg: string, qq?: string, type: QmsgPushType = 'send'): Promise { + async send(msg: string, qq?: string, type: QmsgPushType = 'send'): Promise> { + Debugger('msg: "%s", qq: "%s", type: "%s"', msg, qq, type) return ajax({ url: `https://qmsg.zendee.cn/${type}/${this.QMSG_KEY}`, headers: { diff --git a/src/push/xi-zhi.ts b/src/push/xi-zhi.ts new file mode 100644 index 0000000..5c272a7 --- /dev/null +++ b/src/push/xi-zhi.ts @@ -0,0 +1,40 @@ +import { AxiosResponse } from 'axios' +import debug from 'debug' +import { Send } from '../interfaces/send' +import { ajax } from '@/utils/ajax' + +const Debugger = debug('push:xi-zhi') + +/** + * 息知 推送,官方文档:https://xz.qqoq.net/#/index + * + * @author CaoMeiYouRen + * @date 2022-02-18 + * @export + * @class XiZhi + */ +export class XiZhi implements Send { + private XI_ZHI_KEY: string + + constructor(XI_ZHI_KEY: string) { + this.XI_ZHI_KEY = XI_ZHI_KEY + Debugger('set XI_ZHI_KEY: "%s"', XI_ZHI_KEY) + if (!this.XI_ZHI_KEY) { + throw new Error('XI_ZHI_KEY 是必须的!') + } + } + async send(title: string, content: string = ''): Promise> { + Debugger('title: "%s", content: "%s"', title, content) + return ajax({ + url: `https://xizhi.qqoq.net/${this.XI_ZHI_KEY}.send`, + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + data: { + title, + content, + }, + }) + } +}