Skip to content

Commit

Permalink
feat: 新增 PushPlus 推送支持
Browse files Browse the repository at this point in the history
  • Loading branch information
CaoMeiYouRen committed Mar 2, 2021
1 parent c9a9d0d commit 299ae9f
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export * from './push/dingtalk'
export * from './push/cool-push'
export * from './push/email'
export * from './push/i-got'
export * from './push/push-plus'
export * from './push/server-chan'
export * from './push/server-chan-turbo'
export * from './push/wechat-app'
Expand Down
17 changes: 17 additions & 0 deletions src/push/i-got.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { ajax } from '@/utils/ajax'
import { warn } from '@/utils/helper'
import { AxiosResponse } from 'axios'
import debug from 'debug'
import { Send } from '../interfaces/send'

const Debugger = debug('push:i-got')

export class IGot implements Send {

constructor() { }

send(...args: any[]): Promise<any> {
throw new Error('Method not implemented.')
}

}
63 changes: 63 additions & 0 deletions src/push/push-plus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { ajax } from '@/utils/ajax'
import { warn } from '@/utils/helper'
import { AxiosResponse } from 'axios'
import debug from 'debug'
import { Send } from '../interfaces/send'

const Debugger = debug('push:push-plus')

type TemplateType = 'html' | 'json' | 'cloudMonitor'
/**
* pushplus 推送加开放平台,仅支持一对一推送。官方文档:http://pushplus.hxtrip.com/doc/
*
* @author CaoMeiYouRen
* @date 2021-03-03
* @export
* @class PushPlus
*/
export class PushPlus implements Send {

/**
* 请前往 http://pushplus.hxtrip.com/message 领取
*
* @private
*/
private PUSH_PLUS_TOKEN: string
/**
*
* @author CaoMeiYouRen
* @date 2021-03-03
* @param PUSH_PLUS_TOKEN 请前往 http://pushplus.hxtrip.com/message 领取
*/
constructor(PUSH_PLUS_TOKEN: string) {
this.PUSH_PLUS_TOKEN = PUSH_PLUS_TOKEN
Debugger('set PUSH_PLUS_TOKEN: "%s"', PUSH_PLUS_TOKEN)
if (!this.PUSH_PLUS_TOKEN) {
throw new Error('PUSH_PLUS_TOKEN 是必须的!')
}
}
/**
*
*
* @author CaoMeiYouRen
* @date 2021-03-03
* @param title 消息标题
* @param [content] 具体消息内容,根据不同template支持不同格式
* @param [template='html'] 发送消息模板,默认为 html
* @returns
*/
send(title: string, content?: string, template: TemplateType = 'html'): Promise<AxiosResponse<any>> {
Debugger('content: "%s", content: "%s"', title, content)
return ajax({
url: 'http://pushplus.hxtrip.com/send',
method: 'POST',
data: {
token: this.PUSH_PLUS_TOKEN,
title,
content: content || title,
template,
},
})
}

}

0 comments on commit 299ae9f

Please sign in to comment.