【下载参考项目文件】

local 请求地址 = "https://api.yankami.cn/"
local 项目ID = ""
local 项目版本 = ""
local 项目秘钥 = ""
local 验证超时分钟 = 1440--可调整
local 验证心跳频秒 = 10--可调整
local 验证时间 = false--变量需要 不要调整
local 获取卡密到期时间 = false--变量需要 不要调整
local 设备编号 = getStringConfig("设备编号")

function 获取项目信息()
	local timeStamp = os.time()
	local sign = MD5(项目ID .. 项目秘钥 .. timeStamp);
	local ret, code = httpPost(请求地址 .. "xm", "xmid=" .. 项目ID .. "&timeStamp=" .. timeStamp .. "&sign=" .. sign)
	if code ~= 200 or not (utf8.mid(ret, 1, 1) == "{" and utf8.mid(ret, utf8.length(ret), 1) == "}") then
		print("获取项目信息失败!")
		toast("获取项目信息失败!")
		restartScript()
	end
	ret = jsonLib.decode(ret)
	if ret.code == 201 then
		print("项目不存在!")
		toast("项目不存在!")
		restartScript()
	end
	if ret.code ~= 200 then
		print("获取项目信息失败!")
		toast("获取项目信息失败!")
		restartScript()
	end
	local serviceSign = ret.sign
	local localSign = string.sub(MD5(项目ID .. 项目秘钥 .. encodeBase64(ret.data) .. timeStamp), 1, 4)
	print("serviceSign:" .. serviceSign)
	print("localSign:" .. localSign)
	if not (string.lower(serviceSign) == string.lower(localSign)) then
		print("非法的返回!")
		toast("非法的返回!")
		restartScript()
	end
	local data = jsonLib.decode(ret.data)
	print(data)
	if data.ggzt == 1 then
		print(data.xmgg)
		toast(data.xmgg)
		sleep(1000)
	end
	if data.xmzt == 0 then
		print("项目已经停用!")
		toast("项目已经停用!")
		restartScript()
	end
end

function 获取卡密信息()
	local 账号 = arr.账号
	local 卡密 = arr.卡密
	local timeStamp = os.time()
	if not 获取卡密到期时间 or tickCount() - 验证时间 >= (验证心跳频秒*1000) or 获取卡密到期时间 and timeStamp > 获取卡密到期时间 then
		if not 账号 then
			print("请输入账号!")
			toast("请输入账号!")
			restartScript()
		end
		if not 卡密 then
			print("请输入卡密!")
			toast("请输入卡密!")
			restartScript()
		end
		if utf8.length(设备编号) == 0 then
			设备编号 = "LanRen"..os.time()
			setStringConfig("设备编号",设备编号)
		end
		local sign = MD5(项目ID .. 项目秘钥 .. timeStamp);
		local ret,code = httpPost(请求地址.."km","xmid="..项目ID.."&km="..卡密.."&jqm="..设备编号.."&timeStamp=".. timeStamp.."&sign=".. sign)
		print("获取卡密信息:" .. ret)
		if code ~= 200 or not (utf8.mid(ret,1,1) == "{" and utf8.mid(ret,utf8.length(ret),1) == "}") then
			if not 获取卡密到期时间 or tickCount() - 验证时间 >= (验证超时分钟*1000*60) then
				print("验证失败,请重新运行!")
				toast("验证失败,请重新运行!")
				restartScript()
			end
			if timeStamp > 获取卡密到期时间 then
				print("卡密已经到期!")
				toast("卡密已经到期!")
				restartScript()
			end
		else
			ret = jsonLib.decode(ret)
			if ret.code == 201 then
				print("卡密不存在!")
				toast("卡密不存在!")
				restartScript()
			elseif ret.code == 202 then
				print("项目已经停用!")
				toast("项目已经停用!")
				restartScript()
			elseif ret.code == 203 then
				print("卡密已经到期!")
				toast("卡密已经到期!")
				restartScript()
			elseif ret.code == 204 then
				if not 获取卡密到期时间 then
					print("换绑机器码")
					toast("换绑机器码")
					sleep(1000)
					local timeStamp = os.time()
					local sign = MD5(项目ID .. 项目秘钥 .. timeStamp);
					local ret,code = httpPost(请求地址.."jqm","xmid="..项目ID.."&km="..卡密.."&jqm="..设备编号.."&timeStamp=".. timeStamp.."&sign=".. sign)
					print("换绑机器码:" .. ret)
					if code == 200 and isJsonStr(ret) then
						ret = jsonLib.decode(ret)
					end
					if code ~= 200 or ret.code ~= 200 then
						print("换绑失败,请重试!")
						toast("换绑失败,请重试!")
					else
						print("换绑成功,请重新运行!")
						toast("换绑成功,请重新运行!")
					end
					restartScript()
				else
					while true do
						print("卡密绑定了其他设备!")
						toast("卡密绑定了其他设备!")
						sleep(1000)
					end
				end
			elseif ret.code ~= 200 then
				print("验证失败,请重新运行!")
				toast("验证失败,请重新运行!")
				restartScript()
			else
				local serviceSign = ret.sign
				local localSign = string.sub(MD5(项目ID .. 项目秘钥 .. encodeBase64(ret.data) .. timeStamp), 1, 4)
				print("serviceSign:" .. serviceSign)
				print("localSign:" .. localSign)
				if not (string.lower(serviceSign) == string.lower(localSign)) then
					print("非法的返回!")
					toast("非法的返回!")
					restartScript()
				end
				local data = jsonLib.decode(ret.data)
				if not 获取卡密到期时间 then
					local dqsj = os.date("%Y-%m-%d %H:%M:%S",data.dqsj)
					print("卡密到期日期:"..dqsj)
					toast("卡密到期日期:"..dqsj)
					sleep(1000)
				end
				验证时间 = tickCount()
				获取卡密到期时间 = data.dqsj
			end
		end
	end
end

--验证并休眠
function 验证卡密(ms)
	local 开始时间 = tickCount()
	获取卡密信息()
	local 结束时间 = tickCount()
	local delay = ms + (开始时间 - 结束时间)
	if delay > 0 then
		sleep(delay)
	end
end

function ui()
	--ui 显示页面 宽 高
	关闭回调,arr = showUI("长情云验证.ui",600,600,onLoadEvent,onClickEvent,onCloseEvent,onSelectEvent);
	--print("参数:",arr)
	for i, v in pairs(arr) do
		--print(i.."="..v)
		--多选框选中为0 没选中则为 "" 将 "" 设置为 nil 则 false
		if arr[i] == "" then
			arr[i] = nil
		end
	end
	--确认1 关闭2
	if 关闭回调 == 1 then
		获取项目信息()
        获取卡密信息()
        --主代码
		while true do
        	--循环调用验证
			验证卡密(1000)
		end
		--重启当前脚本
		restartScript()
	else
		print("停止脚本")
		--停止脚本
		exitScript()
	end
end
ui()