Skip to content

Commit

Permalink
feat: 新增 Qmsg 酱推送
Browse files Browse the repository at this point in the history
  • Loading branch information
CaoMeiYouRen committed Feb 17, 2022
1 parent 3545b9f commit 4dc8232
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 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 } from 'push-all-in-one'
import { ServerChanTurbo, CoolPush, Dingtalk, Email, WechatRobot, WechatApp, PushPlus, IGot, Qmsg } from 'push-all-in-one'

// Server酱。官方文档:https://sct.ftqq.com/
const SCTKEY = 'SCTxxxxxxxxxxxxxxxxxxx'
Expand Down Expand Up @@ -101,6 +101,11 @@ const I_GOT_KEY = 'xxxxxxxxxx'
const iGot = new IGot(I_GOT_KEY)
iGot.send('你好', '你好,我很可爱', 'https://github.com/CaoMeiYouRen/push-all-in-one')

// Qmsg 酱 推送,官方文档:https://qmsg.zendee.cn/api.html
const QMSG_KEY = 'xxxxxxxxxxxx'
const qmsg = new Qmsg(QMSG_KEY)
qmsg.send('你好,我很可爱 - Qmsg', '12345,12346', 'send') // msg:要推送的消息内容;qq:指定要接收消息的QQ号或者QQ群,多个以英文逗号分割,例如:12345,12346

```

## 开发
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
export * from './push/dingtalk'
export * from './push/cool-push'
export * from './push/dingtalk'
export * from './push/email'
export * from './push/i-got'
export * from './push/push-plus'
export * from './push/qmsg'
export * from './push/server-chan-turbo'
export * from './push/wechat-app'
export * from './push/wechat-robot'
44 changes: 44 additions & 0 deletions src/push/qmsg.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { AxiosResponse } from 'axios'
import debug from 'debug'
import { Send } from '../interfaces/send'
import { ajax } from '@/utils/ajax'

const Debugger = debug('push:qmsg')

/**
* 推送类型,见 [Qmsg](https://qmsg.zendee.cn/api.html)。
*/
export type QmsgPushType = 'send' | 'group'

/**
* Qmsg酱。使用说明见 [Qmsg酱](https://qmsg.zendee.cn/api.html)
*
* @author CaoMeiYouRen
* @date 2022-02-17
* @export
* @class Qmsg
*/
export class Qmsg implements Send {

private QMSG_KEY: string

constructor(QMSG_KEY: string) {
this.QMSG_KEY = QMSG_KEY
Debugger('set QMSG_KEY: "%s"', QMSG_KEY)
if (!this.QMSG_KEY) {
throw new Error('QMSG_KEY 是必须的!')
}
}

async send(msg: string, qq?: string, type: QmsgPushType = 'send'): Promise<any> {
return ajax({
url: `https://qmsg.zendee.cn/${type}/${this.QMSG_KEY}`,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
method: 'POST',
data: { msg, qq },
})
}

}
2 changes: 1 addition & 1 deletion src/push/wechat-robot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class WechatRobot implements Send {
}
}

async push(message: Msg): Promise<AxiosResponse<any>> {
private async push(message: Msg): Promise<AxiosResponse<any>> {
return ajax({
url: 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send',
headers: {
Expand Down

0 comments on commit 4dc8232

Please sign in to comment.