33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import { Notifier, NotifyParams, NotifyResult, NotifierParam } from './notifier.types';
|
|
|
|
const params: NotifierParam[] = [
|
|
{ key: 'token', label: 'Token', type: 'password', required: true, placeholder: 'pushplus token' },
|
|
|
|
];
|
|
|
|
export const pushplusNotifier: Notifier = {
|
|
name: 'pushplus',
|
|
label: 'PushPlus (微信)',
|
|
params,
|
|
async notify(params) {
|
|
try {
|
|
const resp = await fetch('https://www.pushplus.plus/send', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({
|
|
token: params.token,
|
|
title: params.title || 'CloudSearch',
|
|
content: params.content || '',
|
|
}),
|
|
});
|
|
const data: any = await resp.json();
|
|
if (data.code === 200)
|
|
return { success: true, message: 'PushPlus 推送成功' };
|
|
return { success: false, message: data.msg || `HTTP ${resp.status}` };
|
|
}
|
|
catch (err: any) {
|
|
return { success: false, message: err.message };
|
|
}
|
|
},
|
|
};
|