diff --git a/src/index.ts b/src/index.ts index eb85a2d..7726738 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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' diff --git a/src/push/i-got.ts b/src/push/i-got.ts new file mode 100644 index 0000000..f7be471 --- /dev/null +++ b/src/push/i-got.ts @@ -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 { + throw new Error('Method not implemented.') + } + +} diff --git a/src/push/push-plus.ts b/src/push/push-plus.ts new file mode 100644 index 0000000..f6f898f --- /dev/null +++ b/src/push/push-plus.ts @@ -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> { + 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, + }, + }) + } + +}