local ret = showUI("这里填写你的.ui" , - 1 , - 1)
ret = jsonLib.decode(ret)
kami = ret.page0.inputField1
local https = require("ssl.https")
local ltn12 = require("ltn12")
--卡密用ui获取
local heartbeat_interval = 60 -- 心跳间隔:60秒
local retry_count = 0 -- 心跳重试计数
local max_retry = 3 -- 最大重试次数
local last_heartbeat_time = os.time() -- 记录上次心跳时间(秒级,更直观)
function 卡密心跳(appid)
local https = require("ssl.https")
local ltn12 = require("ltn12")
local 设备码 = getDeviceId()
local 时间戳 = os.time()
local 当前时间 = os.date("%Y-%m-%d %H:%M:%S")
-- 拼接URL+发请求(复用原逻辑)
local url = string.format(
"https://k.duds.cn/api.php?api=heartbeat&app=%s&kami=%s&markcode=%s&t=%d" ,
appid , kami , 设备码 , 时间戳
)
local responseBody = {}
local _ , status , _ , _ = https.request{
url = url , method = "GET" , protocol = "tlsv1_2" , sink = ltn12.sink.table(responseBody)
}
-- 响应处理(保留重试+严重错误退出)
if status == 200 then
local responseStr = table.concat(responseBody)
local ok , data = pcall(jsonLib.decode , responseStr)
if ok and data.code == 200 then
print("心跳成功:" .. data.msg.status .. "\n")
retry_count = 0
else
print("心跳失败:" .. (data.msg or "解析错误") .. "\n")
exitScript()
end
else
print("心跳HTTP错误:状态码" .. status .. "\n")
retry_count = retry_count + 1
end
-- 重试超上限退出
if retry_count > max_retry then
print("心跳重试超3次,脚本停止")
exitScript()
end
-- 更新上次心跳时间(执行完心跳后更新,确保下次间隔60秒)
last_heartbeat_time = os.time()
end
-----这里是调用和自己的脚本融合-------------
while true do
print("我的脚本执行")
sleep(1000)
local 距离上次心跳 = os.time() - last_heartbeat_time
if 距离上次心跳 >= heartbeat_interval then
卡密心跳(10198) -- 到点执行心跳
end
end