import { AxiosResponse } from 'axios' ; import debug from 'debug' ; import { Send } from '../interfaces/send' ; import { MarkdownMsg } from './wechat/MarkdownMsg' ; import { TextMsg } from './wechat/TextMsg' ; import { ajax } from '@/utils/ajax' ; const Debugger = debug ( 'push:wechat-robot' ) ; export type MsgType = 'text' | 'markdown' ; type Msg = TextMsg | MarkdownMsg ; author CaoMeiYouRen
 *  date export class export class WechatRobot implements Send { private WX_ROBOT_KEY : string ; constructor ( WX_ROBOT_KEY ) { this . WX_ROBOT_KEY = WX_ROBOT_KEY ; Debugger ( 'set WX_ROBOT_KEY: "%s"' , WX_ROBOT_KEY ) ; if ( ! this . WX_ROBOT_KEY ) { throw new Error ( 'WX_ROBOT_KEY 是必须的！' ) ; } } async push ( message ) { return ajax ( { url : 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send' , headers : { 'Content-Type' : 'application/json' , } , method : 'POST' , query : { key : this . WX_ROBOT_KEY } , data : { ... message } , } ) ; } author CaoMeiYouRen
     *  date param content param msgtype returns async send ( content , msgtype = 'text' ) { Debugger ( 'content: "%s", msgtype: "%s"' , content , msgtype ) ; switch ( msgtype ) { case 'text' : return this . push ( new TextMsg ( { msgtype : 'text' , text : { content , } , } ) ) ; case 'markdown' : return this . push ( new MarkdownMsg ( { msgtype : 'markdown' , markdown : { content , } , } ) ) ; default : break ; } } }