mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-30 21:06:20 +08:00
补全 wxPusher 推送方式代码
This commit is contained in:
parent
86814de376
commit
47afde667f
|
@ -21,6 +21,7 @@ export enum NotificationMode {
|
|||
'webhook' = 'webhook',
|
||||
'chronocat' = 'Chronocat',
|
||||
'ntfy' = 'ntfy',
|
||||
'wxPusherBot' = 'wxPusherBot',
|
||||
}
|
||||
|
||||
abstract class NotificationBaseInfo {
|
||||
|
@ -145,6 +146,13 @@ export class NtfyNotification extends NotificationBaseInfo {
|
|||
public ntfyTopic = '';
|
||||
public ntfyPriority = '';
|
||||
}
|
||||
|
||||
export class WxPusherBotNotification extends NotificationBaseInfo {
|
||||
public wxPusherBotAppToken = '';
|
||||
public wxPusherBotTopicIds = '';
|
||||
public wxPusherBotUids = '';
|
||||
}
|
||||
|
||||
export interface NotificationInfo
|
||||
extends GoCqHttpBotNotification,
|
||||
GotifyNotification,
|
||||
|
@ -165,5 +173,5 @@ export interface NotificationInfo
|
|||
WebhookNotification,
|
||||
ChronocatNotification,
|
||||
LarkNotification,
|
||||
NtfyNotification {}
|
||||
|
||||
NtfyNotification,
|
||||
WxPusherBotNotification {}
|
||||
|
|
|
@ -36,6 +36,7 @@ export default class NotificationService {
|
|||
['lark', this.lark],
|
||||
['chronocat', this.chronocat],
|
||||
['ntfy', this.ntfy],
|
||||
['wxPusherBot', this.wxPusherBot],
|
||||
]);
|
||||
|
||||
private title = '';
|
||||
|
@ -689,6 +690,51 @@ export default class NotificationService {
|
|||
}
|
||||
}
|
||||
|
||||
private async wxPusherBot() {
|
||||
const { wxPusherBotAppToken, wxPusherBotTopicIds, wxPusherBotUids } = this.params;
|
||||
// 处理 topicIds,将分号分隔的字符串转为数组
|
||||
const topicIds = wxPusherBotTopicIds ? wxPusherBotTopicIds.split(';')
|
||||
.map(id => id.trim())
|
||||
.filter(id => id)
|
||||
.map(id => parseInt(id)) : [];
|
||||
|
||||
// 处理 uids,将分号分隔的字符串转为数组
|
||||
const uids = wxPusherBotUids ? wxPusherBotUids.split(';')
|
||||
.map(uid => uid.trim())
|
||||
.filter(uid => uid) : [];
|
||||
|
||||
// topic_ids 和 uids 至少要有一个
|
||||
if (!topicIds.length && !uids.length) {
|
||||
throw new Error('wxPusher 服务的 TopicIds 和 Uids 至少配置一个才行');
|
||||
}
|
||||
|
||||
const url = `https://wxpusher.zjiecode.com/api/send/message`;
|
||||
try {
|
||||
const res: any = await got
|
||||
.post(url, {
|
||||
...this.gotOption,
|
||||
json: {
|
||||
appToken: wxPusherBotAppToken,
|
||||
content: `<h1>${this.title}</h1><br/><div style='white-space: pre-wrap;'>${this.content}</div>`,
|
||||
summary: this.title,
|
||||
contentType: 2,
|
||||
topicIds: topicIds,
|
||||
uids: uids,
|
||||
verifyPayType: 0
|
||||
},
|
||||
})
|
||||
.json();
|
||||
|
||||
if (res.code === 1000) {
|
||||
return true;
|
||||
} else {
|
||||
throw new Error(JSON.stringify(res));
|
||||
}
|
||||
} catch (error: any) {
|
||||
throw new Error(error.response ? error.response.body : error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private async chronocat() {
|
||||
const { chronocatURL, chronocatQQ, chronocatToken } = this.params;
|
||||
|
|
|
@ -390,6 +390,9 @@
|
|||
"自建的PushMeServer消息接口地址,例如:http://127.0.0.1:3010,不填则使用官方消息接口": "The self built PushMeServer message interface address, for example: http://127.0.0.1:3010 If left blank, use the official message interface",
|
||||
"ntfy的url地址,例如 https://ntfy.sh'": "The URL address of ntfy, for example, https://ntfy.sh.",
|
||||
"ntfy的消息应用topic": "The topic for ntfy's messaging application.",
|
||||
"wxPusherBot的appToken": "wxPusherBot's appToken, obtain according to docs https://wxpusher.zjiecode.com/docs/",
|
||||
"wxPusherBot的topicIds": "wxPusherBot's topicIds, at least one of topicIds or uids must be configured",
|
||||
"wxPusherBot的uids": "wxPusherBot's uids, at least one of topicIds or uids must be configured",
|
||||
"请求方法": "Request Method",
|
||||
"请求头Content-Type": "Request Header Content-Type",
|
||||
"请求链接以http或者https开头。url或者body中必须包含$title,$content可选,对应api内容的位置": "Request URL should start with http or https. URL or body must contain $title, $content is optional and corresponds to the API content position.",
|
||||
|
|
|
@ -390,6 +390,9 @@
|
|||
"自建的PushMeServer消息接口地址,例如:http://127.0.0.1:3010,不填则使用官方消息接口": "自建的PushMeServer消息接口地址,例如:http://127.0.0.1:3010,不填则使用官方消息接口",
|
||||
"ntfy的url地址,例如 https://ntfy.sh": "ntfy的url地址,例如 https://ntfy.sh",
|
||||
"ntfy的消息应用topic": "ntfy的消息应用topic",
|
||||
"wxPusherBot的appToken": "wxPusherBot的appToken, 按照文档获取 https://wxpusher.zjiecode.com/docs/",
|
||||
"wxPusherBot的topicIds": "wxPusherBot的topicIds, topicIds 和 uids 至少配置一个才行",
|
||||
"wxPusherBot的uids": "wxPusherBot的uids, topicIds 和 uids 至少配置一个才行",
|
||||
"请求方法": "请求方法",
|
||||
"请求头Content-Type": "请求头Content-Type",
|
||||
"请求链接以http或者https开头。url或者body中必须包含$title,$content可选,对应api内容的位置": "请求链接以http或者https开头。url或者body中必须包含$title,$content可选,对应api内容的位置",
|
||||
|
|
|
@ -97,6 +97,7 @@ export default {
|
|||
{ value: 'iGot', label: 'IGot' },
|
||||
{ value: 'pushPlus', label: 'PushPlus' },
|
||||
{ value: 'wePlusBot', label: intl.get('微加机器人') },
|
||||
{ value: 'wxPusherBot', label: 'wxPusher' },
|
||||
{ value: 'chat', label: intl.get('群晖chat') },
|
||||
{ value: 'email', label: intl.get('邮箱') },
|
||||
{ value: 'lark', label: intl.get('飞书机器人') },
|
||||
|
@ -348,6 +349,23 @@ export default {
|
|||
),
|
||||
},
|
||||
],
|
||||
wxPusherBot: [
|
||||
{
|
||||
label: 'wxPusherBotAppToken',
|
||||
tip: intl.get('wxPusherBot的appToken'),
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
label: 'wxPusherBotTopicIds',
|
||||
tip: intl.get('wxPusherBot的topicIds'),
|
||||
required: false,
|
||||
},
|
||||
{
|
||||
label: 'wxPusherBotUids',
|
||||
tip: intl.get('wxPusherBot的uids'),
|
||||
required: false,
|
||||
},
|
||||
],
|
||||
lark: [
|
||||
{
|
||||
label: 'larkKey',
|
||||
|
|
Loading…
Reference in New Issue
Block a user