|
@@ -27,9 +27,7 @@ local notify = {
|
|
|
return
|
|
|
end
|
|
|
|
|
|
- local header = {
|
|
|
- ["content-type"] = config.CUSTOM_POST_CONTENT_TYPE
|
|
|
- }
|
|
|
+ local header = { ["content-type"] = config.CUSTOM_POST_CONTENT_TYPE }
|
|
|
|
|
|
local body = json.decode(json.encode(config.CUSTOM_POST_BODY_TABLE))
|
|
|
-- 遍历并替换其中的变量
|
|
@@ -67,14 +65,8 @@ local notify = {
|
|
|
return
|
|
|
end
|
|
|
|
|
|
- local header = {
|
|
|
- ["content-type"] = "application/json"
|
|
|
- }
|
|
|
- local body = {
|
|
|
- ["chat_id"] = config.TELEGRAM_CHAT_ID,
|
|
|
- ["disable_web_page_preview"] = true,
|
|
|
- ["text"] = msg
|
|
|
- }
|
|
|
+ local header = { ["content-type"] = "application/json" }
|
|
|
+ local body = { ["chat_id"] = config.TELEGRAM_CHAT_ID, ["disable_web_page_preview"] = true, ["text"] = msg }
|
|
|
local json_data = json.encode(body)
|
|
|
json_data = string.gsub(json_data, "\\b", "\\n")
|
|
|
|
|
@@ -93,14 +85,8 @@ local notify = {
|
|
|
end
|
|
|
|
|
|
local url = config.GOTIFY_API .. "/message?token=" .. config.GOTIFY_TOKEN
|
|
|
- local header = {
|
|
|
- ["Content-Type"] = "application/json; charset=utf-8"
|
|
|
- }
|
|
|
- local body = {
|
|
|
- title = config.GOTIFY_TITLE,
|
|
|
- message = msg,
|
|
|
- priority = config.GOTIFY_PRIORITY
|
|
|
- }
|
|
|
+ local header = { ["Content-Type"] = "application/json; charset=utf-8" }
|
|
|
+ local body = { title = config.GOTIFY_TITLE, message = msg, priority = config.GOTIFY_PRIORITY }
|
|
|
local json_data = json.encode(body)
|
|
|
json_data = string.gsub(json_data, "\\b", "\\n")
|
|
|
|
|
@@ -118,14 +104,8 @@ local notify = {
|
|
|
return
|
|
|
end
|
|
|
|
|
|
- local header = {
|
|
|
- ["Content-Type"] = "application/x-www-form-urlencoded"
|
|
|
- }
|
|
|
- local body = {
|
|
|
- pushkey = config.PUSHDEER_KEY or "",
|
|
|
- type = "text",
|
|
|
- text = msg
|
|
|
- }
|
|
|
+ local header = { ["Content-Type"] = "application/x-www-form-urlencoded" }
|
|
|
+ local body = { pushkey = config.PUSHDEER_KEY or "", type = "text", text = msg }
|
|
|
|
|
|
log.info("util_notify", "POST", config.PUSHDEER_API)
|
|
|
return util_http.fetch(nil, "POST", config.PUSHDEER_API, header, urlencodeTab(body))
|
|
@@ -141,12 +121,8 @@ local notify = {
|
|
|
return
|
|
|
end
|
|
|
|
|
|
- local header = {
|
|
|
- ["Content-Type"] = "application/x-www-form-urlencoded"
|
|
|
- }
|
|
|
- local body = {
|
|
|
- body = msg
|
|
|
- }
|
|
|
+ local header = { ["Content-Type"] = "application/x-www-form-urlencoded" }
|
|
|
+ local body = { body = msg }
|
|
|
local url = config.BARK_API .. "/" .. config.BARK_KEY
|
|
|
|
|
|
log.info("util_notify", "POST", url)
|
|
@@ -159,15 +135,8 @@ local notify = {
|
|
|
return
|
|
|
end
|
|
|
|
|
|
- local header = {
|
|
|
- ["Content-Type"] = "application/json; charset=utf-8"
|
|
|
- }
|
|
|
- local body = {
|
|
|
- msgtype = "text",
|
|
|
- text = {
|
|
|
- content = msg
|
|
|
- }
|
|
|
- }
|
|
|
+ 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")
|
|
@@ -182,15 +151,8 @@ local notify = {
|
|
|
return
|
|
|
end
|
|
|
|
|
|
- local header = {
|
|
|
- ["Content-Type"] = "application/json; charset=utf-8"
|
|
|
- }
|
|
|
- local body = {
|
|
|
- msg_type = "text",
|
|
|
- content = {
|
|
|
- text = msg
|
|
|
- }
|
|
|
- }
|
|
|
+ local header = { ["Content-Type"] = "application/json; charset=utf-8" }
|
|
|
+ local body = { msg_type = "text", content = { text = msg } }
|
|
|
local json_data = json.encode(body)
|
|
|
-- LuatOS Bug, json.encode 会将 \n 转换为 \b
|
|
|
json_data = string.gsub(json_data, "\\b", "\\n")
|
|
@@ -205,15 +167,8 @@ local notify = {
|
|
|
return
|
|
|
end
|
|
|
|
|
|
- local header = {
|
|
|
- ["Content-Type"] = "application/json; charset=utf-8"
|
|
|
- }
|
|
|
- local body = {
|
|
|
- msgtype = "text",
|
|
|
- text = {
|
|
|
- content = msg
|
|
|
- }
|
|
|
- }
|
|
|
+ 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")
|
|
@@ -232,14 +187,8 @@ local notify = {
|
|
|
return
|
|
|
end
|
|
|
|
|
|
- local header = {
|
|
|
- ["Content-Type"] = "application/json; charset=utf-8"
|
|
|
- }
|
|
|
- local body = {
|
|
|
- token = config.PUSHOVER_API_TOKEN,
|
|
|
- user = config.PUSHOVER_USER_KEY,
|
|
|
- message = msg
|
|
|
- }
|
|
|
+ local header = { ["Content-Type"] = "application/json; charset=utf-8" }
|
|
|
+ local body = { token = config.PUSHOVER_API_TOKEN, user = config.PUSHOVER_USER_KEY, message = msg }
|
|
|
|
|
|
local json_data = json.encode(body)
|
|
|
-- LuatOS Bug, json.encode 会将 \n 转换为 \b
|
|
@@ -293,9 +242,7 @@ local notify = {
|
|
|
return
|
|
|
end
|
|
|
|
|
|
- local header = {
|
|
|
- ["Content-Type"] = "application/x-www-form-urlencoded"
|
|
|
- }
|
|
|
+ local header = { ["Content-Type"] = "application/x-www-form-urlencoded" }
|
|
|
local body = {
|
|
|
user = config.NEXT_SMTP_PROXY_USER,
|
|
|
password = config.NEXT_SMTP_PROXY_PASSWORD,
|
|
@@ -304,7 +251,7 @@ local notify = {
|
|
|
form_name = config.NEXT_SMTP_PROXY_FORM_NAME,
|
|
|
to_email = config.NEXT_SMTP_PROXY_TO_EMAIL,
|
|
|
subject = config.NEXT_SMTP_PROXY_SUBJECT,
|
|
|
- text = msg
|
|
|
+ text = msg,
|
|
|
}
|
|
|
|
|
|
log.info("util_notify", "POST", config.NEXT_SMTP_PROXY_API)
|
|
@@ -318,23 +265,18 @@ local notify = {
|
|
|
password = config.SMTP_PASSWORD,
|
|
|
mail_from = config.SMTP_MAIL_FROM,
|
|
|
mail_to = config.SMTP_MAIL_TO,
|
|
|
- tls_enable = config.SMTP_TLS_ENABLE
|
|
|
+ tls_enable = config.SMTP_TLS_ENABLE,
|
|
|
}
|
|
|
local result = lib_smtp.send(msg, config.SMTP_MAIL_SUBJECT, smtp_config)
|
|
|
log.info("util_notify", "SMTP", result.success, result.message, result.is_retry)
|
|
|
- if result.success then
|
|
|
- return 200, nil, result.message
|
|
|
- end
|
|
|
- if result.is_retry then
|
|
|
- return 500, nil, result.message
|
|
|
- end
|
|
|
+ if result.success then return 200, nil, result.message end
|
|
|
+ if result.is_retry then return 500, nil, result.message end
|
|
|
return 400, nil, result.message
|
|
|
end,
|
|
|
-- 发送到 serial
|
|
|
["serial"] = function(msg)
|
|
|
uart.write(1, msg)
|
|
|
- log.info("util_notify", msg)
|
|
|
- log.info("util_notify", "消息已转发到串口")
|
|
|
+ log.info("util_notify", "serial", "消息已转发到串口")
|
|
|
sys.wait(1000)
|
|
|
return 200
|
|
|
end,
|
|
@@ -345,9 +287,7 @@ local function append()
|
|
|
|
|
|
-- 本机号码
|
|
|
local number = mobile.number(mobile.simid())
|
|
|
- if number then
|
|
|
- msg = msg .. "\n本机号码: " .. number
|
|
|
- end
|
|
|
+ if number then msg = msg .. "\n本机号码: " .. number end
|
|
|
|
|
|
-- 开机时长
|
|
|
local ms = mcu.ticks()
|
|
@@ -357,27 +297,19 @@ local function append()
|
|
|
seconds = seconds % 60
|
|
|
minutes = minutes % 60
|
|
|
local boot_time = string.format("%02d:%02d:%02d", hours, minutes, seconds)
|
|
|
- if ms >= 0 then
|
|
|
- msg = msg .. "\n开机时长: " .. boot_time
|
|
|
- end
|
|
|
+ if ms >= 0 then msg = msg .. "\n开机时长: " .. boot_time end
|
|
|
|
|
|
-- 运营商
|
|
|
local oper = util_mobile.getOper(true)
|
|
|
- if oper ~= "" then
|
|
|
- msg = msg .. "\n运营商: " .. oper
|
|
|
- end
|
|
|
+ if oper ~= "" then msg = msg .. "\n运营商: " .. oper end
|
|
|
|
|
|
-- 信号
|
|
|
local rsrp = mobile.rsrp()
|
|
|
- if rsrp ~= 0 then
|
|
|
- msg = msg .. "\n信号: " .. rsrp .. "dBm"
|
|
|
- end
|
|
|
+ if rsrp ~= 0 then msg = msg .. "\n信号: " .. rsrp .. "dBm" end
|
|
|
|
|
|
-- 频段
|
|
|
local band = util_mobile.getBand()
|
|
|
- if band >= 0 then
|
|
|
- msg = msg .. "\n频段: B" .. band
|
|
|
- end
|
|
|
+ if band >= 0 then msg = msg .. "\n频段: B" .. band end
|
|
|
|
|
|
-- 流量统计
|
|
|
local uplinkGB, uplinkB, downlinkGB, downlinkB = mobile.dataTraffic()
|
|
@@ -428,18 +360,6 @@ function util_notify.send(msg, channel)
|
|
|
return true
|
|
|
end
|
|
|
|
|
|
- -- 通知内容追加更多信息
|
|
|
- -- 若已经包含则不再追加
|
|
|
- local isappend = true
|
|
|
- if string.find(msg,"本机号码:") and string.find(msg,"开机时长:") then
|
|
|
- log.info("util_notify.send", "不追加更多信息")
|
|
|
- isappend = false
|
|
|
- end
|
|
|
-
|
|
|
- if config.NOTIFY_APPEND_MORE_INFO and isappend then
|
|
|
- msg = msg .. append()
|
|
|
- end
|
|
|
-
|
|
|
-- 发送通知
|
|
|
local code, headers, body = notify[channel](msg)
|
|
|
if code == nil then
|
|
@@ -466,22 +386,24 @@ end
|
|
|
-- @param msg 消息内容
|
|
|
-- @param channels 通知渠道
|
|
|
function util_notify.add(msg, channels)
|
|
|
- if type(msg) == "table" then
|
|
|
- msg = table.concat(msg, "\n")
|
|
|
+ if type(msg) == "table" then msg = table.concat(msg, "\n") end
|
|
|
+
|
|
|
+ -- 通知内容追加更多信息, 若已经包含则不再追加
|
|
|
+ local is_append = true
|
|
|
+ if string.find(msg, "本机号码:") and string.find(msg, "开机时长:") then
|
|
|
+ log.info("util_notify.send", "不追加更多信息")
|
|
|
+ is_append = false
|
|
|
end
|
|
|
+ if config.NOTIFY_APPEND_MORE_INFO and is_append then msg = msg .. append() end
|
|
|
|
|
|
channels = channels or config.NOTIFY_TYPE
|
|
|
|
|
|
- if type(channels) ~= "table" then
|
|
|
- channels = {channels}
|
|
|
- end
|
|
|
+ if type(channels) ~= "table" then channels = { channels } end
|
|
|
|
|
|
- for _, channel in ipairs(channels) do
|
|
|
- table.insert(msg_queue, {channel = channel, msg = msg, retry = 0})
|
|
|
- end
|
|
|
+ for _, channel in ipairs(channels) do table.insert(msg_queue, { channel = channel, msg = msg, retry = 0 }) end
|
|
|
sys.publish("NEW_MSG")
|
|
|
log.debug("util_notify.add", "添加到消息队列, 当前队列长度:", #msg_queue)
|
|
|
- log.debug("util_notify.add", "添加到消息队列的内容:", msg)
|
|
|
+ log.debug("util_notify.add", "添加到消息队列的内容:", msg:gsub("\r", "\\r"):gsub("\n", "\\n"))
|
|
|
end
|
|
|
|
|
|
-- 轮询消息队列
|