Skip to content

Commit

Permalink
refactor: 重构 息知推送 到新版接口
Browse files Browse the repository at this point in the history
  • Loading branch information
CaoMeiYouRen committed Nov 8, 2024
1 parent 8d4d7a5 commit 24ffb17
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/push/dingtalk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export interface DingtalkConfig {
DINGTALK_SECRET?: string
}

export interface DingtalkOption {
}

export interface DingtalkResponse {
errcode: number
errmsg: string
Expand Down
24 changes: 20 additions & 4 deletions src/push/xi-zhi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ import { SendResponse } from '@/interfaces/response'

const Debugger = debug('push:xi-zhi')

export interface XiZhiConfig {
// 息知的 key,前往 https://xz.qqoq.net/#/index 获取
XI_ZHI_KEY: string
}

export interface XiZhiOption {
}

export interface XiZhiResponse {
// 状态码,200 表示成功
code: number
msg: string
}

/**
* 息知 推送,官方文档:https://xz.qqoq.net/#/index
*
Expand All @@ -16,15 +30,17 @@ const Debugger = debug('push:xi-zhi')
export class XiZhi implements Send {
private XI_ZHI_KEY: string

constructor(XI_ZHI_KEY: string) {
constructor(config: XiZhiConfig) {
const { XI_ZHI_KEY } = config
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<SendResponse> {
Debugger('title: "%s", content: "%s"', title, content)

async send(title: string, desp?: string): Promise<SendResponse<XiZhiResponse>> {
Debugger('title: "%s", desp: "%s"', title, desp)
return ajax({
url: `https://xizhi.qqoq.net/${this.XI_ZHI_KEY}.send`,
method: 'POST',
Expand All @@ -33,7 +49,7 @@ export class XiZhi implements Send {
},
data: {
title,
content,
content: desp,
},
})
}
Expand Down

0 comments on commit 24ffb17

Please sign in to comment.