Skip to content

Commit

Permalink
feat: 新增 息知 推送
Browse files Browse the repository at this point in the history
  • Loading branch information
CaoMeiYouRen committed Feb 17, 2022
1 parent 4dc8232 commit cfff80b
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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')
```

## 开发
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

3 changes: 2 additions & 1 deletion src/push/qmsg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ export class Qmsg implements Send {
}
}

async send(msg: string, qq?: string, type: QmsgPushType = 'send'): Promise<any> {
async send(msg: string, qq?: string, type: QmsgPushType = 'send'): Promise<AxiosResponse<any>> {
Debugger('msg: "%s", qq: "%s", type: "%s"', msg, qq, type)
return ajax({
url: `https://qmsg.zendee.cn/${type}/${this.QMSG_KEY}`,
headers: {
Expand Down
40 changes: 40 additions & 0 deletions src/push/xi-zhi.ts
Original file line number Diff line number Diff line change
@@ -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<AxiosResponse<any>> {
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,
},
})
}
}

0 comments on commit cfff80b

Please sign in to comment.