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
+7 -2
View File
@@ -241,14 +241,19 @@ export NTFY_PASSWORD=""
export NTFY_ACTIONS=""
## 21. wxPusher
## 官方文档: https://wxpusher.zjiecode.com/docs/
## 管理后台: https://wxpusher.zjiecode.com/admin/
### 方式一:标准发送(更强大)
#### 官方文档: https://wxpusher.zjiecode.com/docs/
#### 管理后台: https://wxpusher.zjiecode.com/admin/
## wxPusher 的 appToken
export WXPUSHER_APP_TOKEN=""
## wxPusher 的 topicIds,多个用英文分号;分隔 topic_ids 与 uids 至少配置一个才行
export WXPUSHER_TOPIC_IDS=""
## wxPusher 的 用户ID,多个用英文分号;分隔 topic_ids 与 uids 至少配置一个才行
export WXPUSHER_UIDS=""
### 方式二:极简发送(最简单,简单好用,一键配置,更推荐)
#### wxPusher 的 SPT(极简推送),扫码获取 https://wxpusher.zjiecode.com/docs/#/?id=spt
#### 多个用英文逗号,分隔,最多10个;与上面的 appToken 方式二选一即可
export WXPUSHER_SPT_LIST=""
## 22. 自定义通知
## 自定义通知 接收回调的URL
+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
]);
}
+56
View File
@@ -133,9 +133,16 @@ push_config = {
'NTFY_PASSWORD': '', # 推送用户密码,可选
'NTFY_ACTIONS': '', # 推送用户动作,可选
### 方式一:标准发送(更强大)
#### 官方文档: https://wxpusher.zjiecode.com/docs/
#### 管理后台: https://wxpusher.zjiecode.com/admin/
'WXPUSHER_APP_TOKEN': '', # wxpusher 的 appToken 官方文档: https://wxpusher.zjiecode.com/docs/ 管理后台: https://wxpusher.zjiecode.com/admin/
'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://wxpusher.zjiecode.com/docs/#/?id=spt
'OPENILINK_APP_TOKEN': '', # OpeniLink 的 app_token,在 OpeniLink Hub 后台安装 App 后获取 官方文档: https://openilink.com/docs/hub/apps
'OPENILINK_HUB_URL': '', # OpeniLink Hub 地址,默认为 https://hub.openilink.com,自建 Hub 时填写自己的地址
@@ -902,6 +909,53 @@ def wxpusher_bot(title: str, content: str) -> None:
print(f"wxpusher 推送失败!错误信息:{response.get('msg')}")
def wxpusher_spt(title: str, content: str) -> None:
"""
通过 wxpusher 极简推送(SPT)推送消息。
支持的环境变量:
- WXPUSHER_SPT_LIST: SPT, 多个用英文逗号,分隔, 最多10个
"""
if not push_config.get("WXPUSHER_SPT_LIST"):
return
# 处理 SPT,将逗号分隔的字符串转为数组
spts = [
spt.strip()
for spt in push_config.get("WXPUSHER_SPT_LIST").split(",")
if spt.strip()
]
if not spts:
print("wxpusher 服务的 WXPUSHER_SPT_LIST 不能为空!!")
return
if len(spts) > 10:
print("wxpusher 服务的 WXPUSHER_SPT_LIST 最多支持 10 个!!")
return
print("wxpusher SPT 服务启动")
url = "https://wxpusher.zjiecode.com/api/send/message/simple-push"
data = {
"content": f"<h1>{title}</h1><br/><div style='white-space: pre-wrap;'>{content}</div>",
"summary": title,
"contentType": 2,
}
# 单个 SPT 用 spt,多个用 sptList
if len(spts) == 1:
data["spt"] = spts[0]
else:
data["sptList"] = spts
headers = {"Content-Type": "application/json"}
response = requests.post(url=url, json=data, headers=headers).json()
if response.get("code") == 1000:
print("wxpusher SPT 推送成功!")
else:
print(f"wxpusher SPT 推送失败!错误信息:{response.get('msg')}")
def openilink(title: str, content: str) -> None:
"""
通过 OpeniLink 推送消息。
@@ -1104,6 +1158,8 @@ def add_notify_function():
push_config.get("WXPUSHER_TOPIC_IDS") or push_config.get("WXPUSHER_UIDS")
):
notify_function.append(wxpusher_bot)
if push_config.get("WXPUSHER_SPT_LIST"):
notify_function.append(wxpusher_spt)
if push_config.get("OPENILINK_APP_TOKEN"):
notify_function.append(openilink)
if not notify_function: