diff --git a/README.md b/README.md index 7f15ae5..9ba4e30 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ - [x] [bark](https://github.com/Finb/Bark) - [x] [dingtalk](https://open.dingtalk.com/document/robots/custom-robot-access) - [x] [feishu](https://open.feishu.cn/document/ukTMukTMukTM/ucTM5YjL3ETO24yNxkjN) + - [x] [wecom](https://developer.work.weixin.qq.com/document/path/91770) - [x] 基站定位 - [x] 定时查询流量 - [x] 开机通知 diff --git a/script/config.lua b/script/config.lua index a693c54..d883356 100644 --- a/script/config.lua +++ b/script/config.lua @@ -1,5 +1,5 @@ return { - -- 通知类型 telegram, pushdeer, bark, dingtalk, feishu + -- 通知类型 telegram, pushdeer, bark, dingtalk, feishu, wecom NOTIFY_TYPE = "pushdeer", -- -- telegram 通知配置, https://github.com/0wQ/telegram-notify @@ -21,6 +21,9 @@ return { -- feishu 通知配置, https://open.feishu.cn/document/ukTMukTMukTM/ucTM5YjL3ETO24yNxkjN FEISHU_WEBHOOK = "", -- + -- wecom 通知配置, https://developer.work.weixin.qq.com/document/path/91770 + WECOM_WEBHOOK = "", + -- -- 定时查询流量间隔, 单位毫秒, 设置为 0 关闭 QUERY_TRAFFIC_INTERVAL = 1000 * 60 * 60 * 6, -- diff --git a/script/util_notify.lua b/script/util_notify.lua index e996905..a04012a 100644 --- a/script/util_notify.lua +++ b/script/util_notify.lua @@ -123,6 +123,30 @@ local function notifyToFeishu(msg) return http.request("POST", config.FEISHU_WEBHOOK, header, json_data).wait() end +-- 发送到 wecom +local function notifyToWeCom(msg) + if config.WECOM_WEBHOOK == nil or config.WECOM_WEBHOOK == "" then + log.error("util_notify.notifyToWeCom", "未配置 `config.WECOM_WEBHOOK`") + return + end + + local header = { + ["Content-Type"] = "application/json; charset=utf-8" + } + local body = { + msgtype = "text", + text = { + content = msg + } + } + local json_data = json.encode(body) + -- LuatOS Bug, json.encode 会将 \n 转换为 \b + json_data = string.gsub(json_data, "\\b", "\\n") + + log.info("util_notify.notifyToWeCom", "POST", config.WECOM_WEBHOOK, json_data) + return http.request("POST", config.WECOM_WEBHOOK, header, json_data).wait() +end + function util_notify.send(msg) log.info("util_notify.send", "发送通知", config.NOTIFY_TYPE) @@ -173,6 +197,8 @@ function util_notify.send(msg) notify = notifyToDingTalk elseif config.NOTIFY_TYPE == "feishu" then notify = notifyToFeishu + elseif config.NOTIFY_TYPE == "wecom" then + notify = notifyToWeCom else log.error("util_notify.send", "发送通知失败", "未配置 `config.NOTIFY_TYPE`") return