From cef3de249475f5907b2515c0db063601cf683260 Mon Sep 17 00:00:00 2001 From: Redbean_Cn <810517583@qq.com> Date: Thu, 29 Jan 2026 16:33:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E4=BC=81=E4=B8=9A?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E6=8E=A8=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sign_ninebot.js | 55 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/sign_ninebot.js b/sign_ninebot.js index cf98ada..759f642 100644 --- a/sign_ninebot.js +++ b/sign_ninebot.js @@ -279,6 +279,57 @@ async function sendBarkNotification(title, message) { return false; } } +// 企业微信推送函数 +async function sendWeComNotification(title, message) { + const corpId = process.env.WECOM_CORP_ID; + const corpSecret = process.env.WECOM_CORP_SECRET; + const toUser = process.env.WECOM_TO_USER; + const agentId = process.env.WECOM_AGENT_ID; + + if (!corpId || !corpSecret || !toUser || !agentId) { + console.error("企业微信配置不完整,跳过通知"); + return false; + } + + try { + // 获取access_token + const tokenResponse = await axios.get( + `https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=${corpId}&corpsecret=${corpSecret}` + ); + + if (tokenResponse.data.errcode !== 0) { + throw new Error(`获取token失败: ${tokenResponse.data.errmsg}`); + } + + const accessToken = tokenResponse.data.access_token; + + // 发送消息 + const data = { + touser: toUser, + msgtype: "text", + text: { + content: `${title}\n\n${message}` + }, + agentid: parseInt(agentId) + }; + + const sendResponse = await axios.post( + `https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=${accessToken}`, + data + ); + + if (sendResponse.data.errcode === 0) { + console.log("企业微信通知发送成功"); + return true; + } else { + console.error("企业微信通知发送失败:", sendResponse.data.errmsg); + return false; + } + } catch (error) { + console.error("发送企业微信通知异常:", error.message); + return false; + } +} // 初始化并执行签到 async function init() { @@ -340,7 +391,9 @@ async function init() { // 发送Bark通知 await sendBarkNotification(title, message); + // 调用企业微信推送 + await sendWeComNotification(title, message); } // 启动执行 -init(); \ No newline at end of file +init();