Add WxPusher simple push support,Enhance user experience and reduce configuration complexity (#3023)

* 新增对WxPusher极简推送的支持,减小用户使用成本

* 新增脚本对WxPusher极简推送的支持

* 修复通知配置的枚举定义

---------

Co-authored-by: zjiecode <zjiecode@gmail.com>
This commit is contained in:
zjiecode
2026-06-30 14:30:31 +08:00
committed by GitHub
parent d3016431ce
commit 327c3a317b
13 changed files with 220 additions and 3 deletions
+64
View File
@@ -147,11 +147,16 @@ const push_config = {
NTFY_PASSWORD: '', // 推送用户密码,可选
NTFY_ACTIONS: '', // 推送用户动作,可选
// 方式一:标准发送(更强大)
// 官方文档: https://wxpusher.zjiecode.com/docs/
// 管理后台: https://wxpusher.zjiecode.com/admin/
WXPUSHER_APP_TOKEN: '', // wxpusher 的 appToken
WXPUSHER_TOPIC_IDS: '', // wxpusher 的 主题ID,多个用英文分号;分隔 topic_ids 与 uids 至少配置一个才行
WXPUSHER_UIDS: '', // wxpusher 的 用户ID,多个用英文分号;分隔 topic_ids 与 uids 至少配置一个才行
// 方式二:极简发送(最简单,简单好用,一键配置,更推荐)
// wxPusher 的 SPT(极简推送),扫码获取 https://wxpusher.zjiecode.com/docs/#/?id=spt
// 多个用英文逗号,分隔,最多10个;与上面的 appToken 方式二选一即可
WXPUSHER_SPT_LIST: '', // wxpusher 的 SPT(极简推送),多个用英文逗号,分隔,最多10个
// 官方文档: https://openilink.com/docs/hub/apps
OPENILINK_APP_TOKEN: '', // OpeniLink 的 app_token,在 OpeniLink Hub 后台安装 App 后获取
@@ -1431,6 +1436,64 @@ function wxPusherNotify(text, desp) {
});
}
function wxPusherSptNotify(text, desp) {
return new Promise((resolve) => {
const { WXPUSHER_SPT_LIST } = push_config;
if (WXPUSHER_SPT_LIST) {
// 处理 SPT,将逗号分隔的字符串转为数组
const spts = WXPUSHER_SPT_LIST.split(',')
.map((spt) => spt.trim())
.filter((spt) => spt);
if (!spts.length) {
console.log('wxpusher SPT 不能为空!!');
return resolve();
}
if (spts.length > 10) {
console.log('wxpusher SPT 最多支持 10 个!!');
return resolve();
}
const body = {
content: `<h1>${text}</h1><br/><div style='white-space: pre-wrap;'>${desp}</div>`,
summary: text,
contentType: 2,
// 单个 SPT 用 spt,多个用 sptList
...(spts.length === 1 ? { spt: spts[0] } : { sptList: spts }),
};
const options = {
url: 'https://wxpusher.zjiecode.com/api/send/message/simple-push',
body: JSON.stringify(body),
headers: {
'Content-Type': 'application/json',
},
timeout,
};
$.post(options, (err, resp, data) => {
try {
if (err) {
console.log('wxpusher SPT 发送通知消息失败!\n', err);
} else {
if (data.code === 1000) {
console.log('wxpusher SPT 发送通知消息完成!');
} else {
console.log(`wxpusher SPT 发送通知消息异常:${data.msg}`);
}
}
} catch (e) {
$.logErr(e, resp);
} finally {
resolve(data);
}
});
} else {
resolve();
}
});
}
function openiLinkNotify(text, desp) {
return new Promise((resolve) => {
const { OPENILINK_APP_TOKEN, OPENILINK_HUB_URL, OPENILINK_CONTEXT_TOKEN } =
@@ -1609,6 +1672,7 @@ async function sendNotify(text, desp, params = {}) {
qmsgNotify(text, desp), // 自定义通知
ntfyNotify(text, desp), // Ntfy
wxPusherNotify(text, desp), // wxpusher
wxPusherSptNotify(text, desp), // wxpusher SPT
openiLinkNotify(text, desp), // OpeniLink
]);
}