|
@@ -1,3 +1,5 @@
|
|
|
|
+local lib_smtp = require "lib_smtp"
|
|
|
|
+
|
|
local util_notify = {}
|
|
local util_notify = {}
|
|
|
|
|
|
-- 消息队列
|
|
-- 消息队列
|
|
@@ -14,22 +16,62 @@ local function urlencodeTab(params)
|
|
end
|
|
end
|
|
|
|
|
|
local notify = {
|
|
local notify = {
|
|
|
|
+ -- 发送到 custom_post
|
|
|
|
+ ["custom_post"] = function(msg)
|
|
|
|
+ if config.CUSTOM_POST_URL == nil or config.CUSTOM_POST_URL == "" then
|
|
|
|
+ log.error("util_notify", "未配置 `config.CUSTOM_POST_URL`")
|
|
|
|
+ return
|
|
|
|
+ end
|
|
|
|
+ if type(config.CUSTOM_POST_BODY_TABLE) ~= "table" then
|
|
|
|
+ log.error("util_notify", "未配置 `config.CUSTOM_POST_BODY_TABLE`")
|
|
|
|
+ return
|
|
|
|
+ end
|
|
|
|
+
|
|
|
|
+ local header = { ["content-type"] = config.CUSTOM_POST_CONTENT_TYPE }
|
|
|
|
+
|
|
|
|
+ local body = json.decode(json.encode(config.CUSTOM_POST_BODY_TABLE))
|
|
|
|
+ -- 遍历并替换其中的变量
|
|
|
|
+ local function traverse_and_replace(t)
|
|
|
|
+ for k, v in pairs(t) do
|
|
|
|
+ if type(v) == "table" then
|
|
|
|
+ traverse_and_replace(v)
|
|
|
|
+ elseif type(v) == "string" then
|
|
|
|
+ t[k] = string.gsub(v, "{msg}", msg)
|
|
|
|
+ end
|
|
|
|
+ end
|
|
|
|
+ end
|
|
|
|
+ traverse_and_replace(body)
|
|
|
|
+
|
|
|
|
+ -- 根据 content-type 进行编码, 默认为 application/x-www-form-urlencoded
|
|
|
|
+ if string.find(config.CUSTOM_POST_CONTENT_TYPE, "json") then
|
|
|
|
+ body = json.encode(body)
|
|
|
|
+ -- LuatOS Bug, json.encode 会将 \n 转换为 \b
|
|
|
|
+ body = string.gsub(body, "\\b", "\\n")
|
|
|
|
+ else
|
|
|
|
+ body = urlencodeTab(body)
|
|
|
|
+ end
|
|
|
|
+
|
|
|
|
+ log.info("util_notify", "POST", config.CUSTOM_POST_URL, config.CUSTOM_POST_CONTENT_TYPE, body)
|
|
|
|
+ return util_http.fetch(nil, "POST", config.CUSTOM_POST_URL, header, body)
|
|
|
|
+ end,
|
|
-- 发送到 telegram
|
|
-- 发送到 telegram
|
|
["telegram"] = function(msg)
|
|
["telegram"] = function(msg)
|
|
- if config.TELEGRAM_PROXY_API == nil or config.TELEGRAM_PROXY_API == "" then
|
|
|
|
- log.error("util_notify", "未配置 `config.TELEGRAM_PROXY_API`")
|
|
|
|
|
|
+ if config.TELEGRAM_API == nil or config.TELEGRAM_API == "" then
|
|
|
|
+ log.error("util_notify", "未配置 `config.TELEGRAM_API`")
|
|
|
|
+ return
|
|
|
|
+ end
|
|
|
|
+ if config.TELEGRAM_CHAT_ID == nil or config.TELEGRAM_CHAT_ID == "" then
|
|
|
|
+ log.error("util_notify", "未配置 `config.TELEGRAM_CHAT_ID`")
|
|
return
|
|
return
|
|
end
|
|
end
|
|
|
|
|
|
- local header = {
|
|
|
|
- ["content-type"] = "text/plain",
|
|
|
|
- ["x-disable-web-page-preview"] = "1",
|
|
|
|
- ["x-chat-id"] = config.TELEGRAM_CHAT_ID or "",
|
|
|
|
- ["x-token"] = config.TELEGRAM_TOKEN or ""
|
|
|
|
- }
|
|
|
|
|
|
+ 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")
|
|
|
|
|
|
- log.info("util_notify", "POST", config.TELEGRAM_PROXY_API)
|
|
|
|
- return util_http.fetch(nil, "POST", config.TELEGRAM_PROXY_API, header, msg)
|
|
|
|
|
|
+ log.info("util_notify", "POST", config.TELEGRAM_API)
|
|
|
|
+ return util_http.fetch(nil, "POST", config.TELEGRAM_API, header, json_data)
|
|
end,
|
|
end,
|
|
-- 发送到 gotify
|
|
-- 发送到 gotify
|
|
["gotify"] = function(msg)
|
|
["gotify"] = function(msg)
|
|
@@ -43,16 +85,10 @@ local notify = {
|
|
end
|
|
end
|
|
|
|
|
|
local url = config.GOTIFY_API .. "/message?token=" .. config.GOTIFY_TOKEN
|
|
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)
|
|
local json_data = json.encode(body)
|
|
- json_data = string.gsub(json_data, "\\b", "\\n")
|
|
|
|
|
|
+ -- json_data = string.gsub(json_data, "\\b", "\\n")
|
|
|
|
|
|
log.info("util_notify", "POST", config.GOTIFY_API)
|
|
log.info("util_notify", "POST", config.GOTIFY_API)
|
|
return util_http.fetch(nil, "POST", url, header, json_data)
|
|
return util_http.fetch(nil, "POST", url, header, json_data)
|
|
@@ -68,14 +104,8 @@ local notify = {
|
|
return
|
|
return
|
|
end
|
|
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)
|
|
log.info("util_notify", "POST", config.PUSHDEER_API)
|
|
return util_http.fetch(nil, "POST", config.PUSHDEER_API, header, urlencodeTab(body))
|
|
return util_http.fetch(nil, "POST", config.PUSHDEER_API, header, urlencodeTab(body))
|
|
@@ -91,12 +121,8 @@ local notify = {
|
|
return
|
|
return
|
|
end
|
|
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
|
|
local url = config.BARK_API .. "/" .. config.BARK_KEY
|
|
|
|
|
|
log.info("util_notify", "POST", url)
|
|
log.info("util_notify", "POST", url)
|
|
@@ -109,21 +135,20 @@ local notify = {
|
|
return
|
|
return
|
|
end
|
|
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")
|
|
|
|
|
|
+ local url = config.DINGTALK_WEBHOOK
|
|
|
|
+ -- 如果配置了 config.DINGTALK_SECRET 则需要签名(加签), 没配置则为自定义关键词
|
|
|
|
+ if (config.DINGTALK_SECRET ~= nil and config.DINGTALK_SECRET ~= "") then
|
|
|
|
+ local timestamp = tostring(os.time()) .. "000"
|
|
|
|
+ local sign = crypto.hmac_sha256(timestamp .. "\n" .. config.DINGTALK_SECRET, config.DINGTALK_SECRET):fromHex():toBase64():urlEncode()
|
|
|
|
+ url = url .. "×tamp=" .. timestamp .. "&sign=" .. sign
|
|
|
|
+ end
|
|
|
|
|
|
- log.info("util_notify", "POST", config.DINGTALK_WEBHOOK)
|
|
|
|
- return util_http.fetch(nil, "POST", config.DINGTALK_WEBHOOK, header, json_data)
|
|
|
|
|
|
+ local header = { ["Content-Type"] = "application/json; charset=utf-8" }
|
|
|
|
+ local body = { msgtype = "text", text = { content = msg } }
|
|
|
|
+ body = json.encode(body)
|
|
|
|
+
|
|
|
|
+ log.info("util_notify", "POST", url)
|
|
|
|
+ return util_http.fetch(nil, "POST", url, header, body)
|
|
end,
|
|
end,
|
|
-- 发送到 feishu
|
|
-- 发送到 feishu
|
|
["feishu"] = function(msg)
|
|
["feishu"] = function(msg)
|
|
@@ -132,18 +157,11 @@ local notify = {
|
|
return
|
|
return
|
|
end
|
|
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)
|
|
local json_data = json.encode(body)
|
|
-- LuatOS Bug, json.encode 会将 \n 转换为 \b
|
|
-- LuatOS Bug, json.encode 会将 \n 转换为 \b
|
|
- json_data = string.gsub(json_data, "\\b", "\\n")
|
|
|
|
|
|
+ -- json_data = string.gsub(json_data, "\\b", "\\n")
|
|
|
|
|
|
log.info("util_notify", "POST", config.FEISHU_WEBHOOK)
|
|
log.info("util_notify", "POST", config.FEISHU_WEBHOOK)
|
|
return util_http.fetch(nil, "POST", config.FEISHU_WEBHOOK, header, json_data)
|
|
return util_http.fetch(nil, "POST", config.FEISHU_WEBHOOK, header, json_data)
|
|
@@ -155,18 +173,11 @@ local notify = {
|
|
return
|
|
return
|
|
end
|
|
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)
|
|
local json_data = json.encode(body)
|
|
-- LuatOS Bug, json.encode 会将 \n 转换为 \b
|
|
-- LuatOS Bug, json.encode 会将 \n 转换为 \b
|
|
- json_data = string.gsub(json_data, "\\b", "\\n")
|
|
|
|
|
|
+ -- json_data = string.gsub(json_data, "\\b", "\\n")
|
|
|
|
|
|
log.info("util_notify", "POST", config.WECOM_WEBHOOK)
|
|
log.info("util_notify", "POST", config.WECOM_WEBHOOK)
|
|
return util_http.fetch(nil, "POST", config.WECOM_WEBHOOK, header, json_data)
|
|
return util_http.fetch(nil, "POST", config.WECOM_WEBHOOK, header, json_data)
|
|
@@ -182,18 +193,12 @@ local notify = {
|
|
return
|
|
return
|
|
end
|
|
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)
|
|
local json_data = json.encode(body)
|
|
-- LuatOS Bug, json.encode 会将 \n 转换为 \b
|
|
-- LuatOS Bug, json.encode 会将 \n 转换为 \b
|
|
- json_data = string.gsub(json_data, "\\b", "\\n")
|
|
|
|
|
|
+ -- json_data = string.gsub(json_data, "\\b", "\\n")
|
|
|
|
|
|
local url = "https://api.pushover.net/1/messages.json"
|
|
local url = "https://api.pushover.net/1/messages.json"
|
|
|
|
|
|
@@ -243,9 +248,7 @@ local notify = {
|
|
return
|
|
return
|
|
end
|
|
end
|
|
|
|
|
|
- local header = {
|
|
|
|
- ["Content-Type"] = "application/x-www-form-urlencoded"
|
|
|
|
- }
|
|
|
|
|
|
+ local header = { ["Content-Type"] = "application/x-www-form-urlencoded" }
|
|
local body = {
|
|
local body = {
|
|
user = config.NEXT_SMTP_PROXY_USER,
|
|
user = config.NEXT_SMTP_PROXY_USER,
|
|
password = config.NEXT_SMTP_PROXY_PASSWORD,
|
|
password = config.NEXT_SMTP_PROXY_PASSWORD,
|
|
@@ -254,22 +257,43 @@ local notify = {
|
|
form_name = config.NEXT_SMTP_PROXY_FORM_NAME,
|
|
form_name = config.NEXT_SMTP_PROXY_FORM_NAME,
|
|
to_email = config.NEXT_SMTP_PROXY_TO_EMAIL,
|
|
to_email = config.NEXT_SMTP_PROXY_TO_EMAIL,
|
|
subject = config.NEXT_SMTP_PROXY_SUBJECT,
|
|
subject = config.NEXT_SMTP_PROXY_SUBJECT,
|
|
- text = msg
|
|
|
|
|
|
+ text = msg,
|
|
}
|
|
}
|
|
|
|
|
|
log.info("util_notify", "POST", config.NEXT_SMTP_PROXY_API)
|
|
log.info("util_notify", "POST", config.NEXT_SMTP_PROXY_API)
|
|
return util_http.fetch(nil, "POST", config.NEXT_SMTP_PROXY_API, header, urlencodeTab(body))
|
|
return util_http.fetch(nil, "POST", config.NEXT_SMTP_PROXY_API, header, urlencodeTab(body))
|
|
- end
|
|
|
|
|
|
+ end,
|
|
|
|
+ ["smtp"] = function(msg)
|
|
|
|
+ local smtp_config = {
|
|
|
|
+ host = config.SMTP_HOST,
|
|
|
|
+ port = config.SMTP_PORT,
|
|
|
|
+ username = config.SMTP_USERNAME,
|
|
|
|
+ password = config.SMTP_PASSWORD,
|
|
|
|
+ mail_from = config.SMTP_MAIL_FROM,
|
|
|
|
+ mail_to = config.SMTP_MAIL_TO,
|
|
|
|
+ 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
|
|
|
|
+ return 400, nil, result.message
|
|
|
|
+ end,
|
|
|
|
+ -- 发送到 serial
|
|
|
|
+ ["serial"] = function(msg)
|
|
|
|
+ uart.write(1, msg)
|
|
|
|
+ log.info("util_notify", "serial", "消息已转发到串口")
|
|
|
|
+ sys.wait(1000)
|
|
|
|
+ return 200
|
|
|
|
+ end,
|
|
}
|
|
}
|
|
|
|
|
|
local function append()
|
|
local function append()
|
|
local msg = "\n"
|
|
local msg = "\n"
|
|
|
|
|
|
-- 本机号码
|
|
-- 本机号码
|
|
- local number = mobile.number(mobile.simid())
|
|
|
|
- if number then
|
|
|
|
- msg = msg .. "\n本机号码: " .. number
|
|
|
|
- end
|
|
|
|
|
|
+ local number = mobile.number(mobile.simid()) or config.FALLBACK_LOCAL_NUMBER
|
|
|
|
+ if number then msg = msg .. "\n本机号码: " .. number end
|
|
|
|
|
|
-- 开机时长
|
|
-- 开机时长
|
|
local ms = mcu.ticks()
|
|
local ms = mcu.ticks()
|
|
@@ -279,43 +303,35 @@ local function append()
|
|
seconds = seconds % 60
|
|
seconds = seconds % 60
|
|
minutes = minutes % 60
|
|
minutes = minutes % 60
|
|
local boot_time = string.format("%02d:%02d:%02d", hours, minutes, seconds)
|
|
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)
|
|
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()
|
|
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()
|
|
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()
|
|
|
|
- uplinkB = uplinkGB * 1024 * 1024 * 1024 + uplinkB
|
|
|
|
- downlinkB = downlinkGB * 1024 * 1024 * 1024 + downlinkB
|
|
|
|
- local function formatBytes(bytes)
|
|
|
|
- if bytes < 1024 then
|
|
|
|
- return bytes .. "B"
|
|
|
|
- elseif bytes < 1024 * 1024 then
|
|
|
|
- return string.format("%.2fKB", bytes / 1024)
|
|
|
|
- elseif bytes < 1024 * 1024 * 1024 then
|
|
|
|
- return string.format("%.2fMB", bytes / 1024 / 1024)
|
|
|
|
- else
|
|
|
|
- return string.format("%.2fGB", bytes / 1024 / 1024 / 1024)
|
|
|
|
- end
|
|
|
|
- end
|
|
|
|
|
|
+ -- local uplinkGB, uplinkB, downlinkGB, downlinkB = mobile.dataTraffic()
|
|
|
|
+ -- uplinkB = uplinkGB * 1024 * 1024 * 1024 + uplinkB
|
|
|
|
+ -- downlinkB = downlinkGB * 1024 * 1024 * 1024 + downlinkB
|
|
|
|
+ -- local function formatBytes(bytes)
|
|
|
|
+ -- if bytes < 1024 then
|
|
|
|
+ -- return bytes .. "B"
|
|
|
|
+ -- elseif bytes < 1024 * 1024 then
|
|
|
|
+ -- return string.format("%.2fKB", bytes / 1024)
|
|
|
|
+ -- elseif bytes < 1024 * 1024 * 1024 then
|
|
|
|
+ -- return string.format("%.2fMB", bytes / 1024 / 1024)
|
|
|
|
+ -- else
|
|
|
|
+ -- return string.format("%.2fGB", bytes / 1024 / 1024 / 1024)
|
|
|
|
+ -- end
|
|
|
|
+ -- end
|
|
-- msg = msg .. "\n流量: ↑" .. formatBytes(uplinkB) .. " ↓" .. formatBytes(downlinkB)
|
|
-- msg = msg .. "\n流量: ↑" .. formatBytes(uplinkB) .. " ↓" .. formatBytes(downlinkB)
|
|
|
|
|
|
-- 位置
|
|
-- 位置
|
|
@@ -350,11 +366,6 @@ function util_notify.send(msg, channel)
|
|
return true
|
|
return true
|
|
end
|
|
end
|
|
|
|
|
|
- -- 通知内容追加更多信息
|
|
|
|
- if config.NOTIFY_APPEND_MORE_INFO then
|
|
|
|
- msg = msg .. append()
|
|
|
|
- end
|
|
|
|
-
|
|
|
|
-- 发送通知
|
|
-- 发送通知
|
|
local code, headers, body = notify[channel](msg)
|
|
local code, headers, body = notify[channel](msg)
|
|
if code == nil then
|
|
if code == nil then
|
|
@@ -381,21 +392,24 @@ end
|
|
-- @param msg 消息内容
|
|
-- @param msg 消息内容
|
|
-- @param channels 通知渠道
|
|
-- @param channels 通知渠道
|
|
function util_notify.add(msg, 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
|
|
end
|
|
|
|
+ if config.NOTIFY_APPEND_MORE_INFO and is_append then msg = msg .. append() end
|
|
|
|
|
|
channels = channels or config.NOTIFY_TYPE
|
|
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")
|
|
sys.publish("NEW_MSG")
|
|
log.debug("util_notify.add", "添加到消息队列, 当前队列长度:", #msg_queue)
|
|
log.debug("util_notify.add", "添加到消息队列, 当前队列长度:", #msg_queue)
|
|
|
|
+ log.debug("util_notify.add", "添加到消息队列的内容:", msg:gsub("\r", "\\r"):gsub("\n", "\\n"))
|
|
end
|
|
end
|
|
|
|
|
|
-- 轮询消息队列
|
|
-- 轮询消息队列
|
|
@@ -403,9 +417,23 @@ end
|
|
-- 发送失败则等待下次轮询
|
|
-- 发送失败则等待下次轮询
|
|
local function poll()
|
|
local function poll()
|
|
local item, result
|
|
local item, result
|
|
|
|
+ local codes = {
|
|
|
|
+ [0] = "网络未注册",
|
|
|
|
+ [1] = "网络已注册",
|
|
|
|
+ [2] = "网络搜索中",
|
|
|
|
+ [3] = "网络注册被拒绝",
|
|
|
|
+ [4] = "网络状态未知",
|
|
|
|
+ [5] = "网络已注册,漫游",
|
|
|
|
+ [6] = "网络已注册,仅SMS",
|
|
|
|
+ [7] = "网络已注册,漫游,仅SMS",
|
|
|
|
+ [8] = "网络已注册,紧急服务",
|
|
|
|
+ [9] = "网络已注册,非主要服务",
|
|
|
|
+ [10] = "网络已注册,非主要服务,漫游",
|
|
|
|
+ }
|
|
while true do
|
|
while true do
|
|
-- 消息队列非空, 且网络已注册
|
|
-- 消息队列非空, 且网络已注册
|
|
- if next(msg_queue) ~= nil and mobile.status() == 1 then
|
|
|
|
|
|
+ log.debug("mobile.status:", codes[mobile.status() or 0] or "未知网络状态")
|
|
|
|
+ if next(msg_queue) ~= nil and (mobile.status() == 1 or mobile.status() == 5) then
|
|
log.debug("util_notify.poll", "轮询消息队列中, 当前队列长度:", #msg_queue)
|
|
log.debug("util_notify.poll", "轮询消息队列中, 当前队列长度:", #msg_queue)
|
|
|
|
|
|
item = msg_queue[1]
|
|
item = msg_queue[1]
|