
local function RsNxZeIy4B8W07E()
fuhao= '"' local stringsub = string.sub local wytonumber = tonumber local wytostring = tostring local stringbyte = string.byte local mathfloor = math.floor local stringlower = string.lower local mathmodf = math.modf local stringupper = string.upper local stringchar = string.char local wypairs = pairs local stringformat = string.format local stringlen = string.len local wyrequest = gg.makeRequest local function json2true(str,from,to) return true, from+3 end local function json2false(str,from,to) return false, from+4 end local function json2null(str, from, to) return nil, from+3 end local function json2nan(str, from, to) return nul, from+2 end local numberchars = {['-'] = true,['+'] = true,['.'] = true,['0'] = true,['1'] = true,['2'] = true,['3'] = true,['4'] = true,['5'] = true,['6'] = true,['7'] = true,['8'] = true,['9'] = true} local function json2number(str,from,to) local i = from+1 while(i<=to) do local char = stringsub(str, i, i) if not numberchars[char] then break end i = i + 1 end local num = wytonumber(stringsub(str, from, i-1)) if not num then error(_format('json格式错误，不正确的数字, 错误位置:{from}', from)) end return num, i-1 end local function json2string(str,from,to) local ignor = false for i = from+1, to do local char = stringsub(str, i, i) if not ignor then if char ==  fuhao  then return stringsub(str, from+1, i-1), i elseif char == '\\' then ignor = true end else ignor = false end end error(_format('json格式错误，字符串没有找到结尾, 错误位置:{from}', from)) end local function json2array(str,from,to)    local result = {}    from = from or 1    local pos = from+1    local to = to or stringlen(str)    while(pos<=to) do        local char = stringsub(str, pos, pos)        if char ==  fuhao  then            result[#result+1], pos = json2string(str,pos,to)        elseif char == '[' then            result[#result+1], pos = json2array(str,pos,to)        elseif char == '{' then            result[#result+1], pos = json2table(str,pos,to)        elseif char == ']' then            return result, pos        elseif (char=='f' or char=='F') then            result[#result+1], pos = json2false(str,pos,to)        elseif (char=='t' or char=='T') then            result[#result+1], pos = json2true(str,pos,to)        elseif (char=='n') then            result[#result+1], pos = json2null(str,pos,to)        elseif (char=='N') then            result[#result+1], pos = json2nan(str,pos,to)        elseif numberchars[char] then            result[#result+1], pos = json2number(str,pos,to)        end        pos = pos + 1    end    error(_format('json格式错误，表没有找到结尾, 错误位置:{from}', from)) end function _G.json2table(str,from,to)    local result = {}    from = from or 1    local pos = from+1    local to = to or stringlen(str)    local key    while(pos<=to) do        local char = stringsub(str, pos, pos)        if char ==  fuhao  then            if not key then                key, pos = json2string(str,pos,to)            else                result[key], pos = json2string(str,pos,to)                key = nil            end        elseif char == '[' then            if not key then                key, pos = json2array(str,pos,to)            else                result[key], pos = json2array(str,pos,to)                key = nil            end        elseif char == '{' then            if not key then                key, pos = json2table(str,pos,to)            else                result[key], pos = json2table(str,pos,to)                key = nil            end        elseif char == '}' then            return result, pos        elseif (char=='f' or char=='F') then            result[key], pos = json2false(str,pos,to)            key = nil        elseif (char=='t' or char=='T') then            result[key], pos = json2true(str,pos,to)            key = nil        elseif (char=='n') then            result[key], pos = json2null(str,pos,to)            key = nil        elseif (char=='N') then            result[key], pos = json2nan(str,pos,to)            key = nil        elseif numberchars[char] then            if not key then                key, pos = json2number(str,pos,to)            else                result[key], pos = json2number(str,pos,to)                key = nil            end        end        pos = pos + 1    end    error(_format('格式错误，表没有找到结尾, 错误位置:{from}', from)) end local jsonfuncs={[ fuhao ]=json2string,['[']=json2array,['{']=json2table,['f']=json2false,['F']=json2false,['t']=json2true,['T']=json2true} local function Q5iJNZ8gWd6hF8e(str) if str==nil then gg.alert('错误json') else local char = stringsub(str, 1, 1) local func=jsonfuncs[char] if func then return func(str, 1, stringlen(str)) end if numberchars[char] then return json2number(str, 1, stringlen(str)) end end end
local function md5(code) local code = wytostring(code) local HexTable = {"0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"} local A = 0x67452301 local B = 0xefcdab89 local C = 0x98badcfe local D = 0x10325476 local S11 = 7 local S12 = 12 local S13 = 17 local S14 = 22 local S21 = 5 local S22 = 9 local S23 = 14 local S24 = 20 local S31 = 4 local S32 = 11 local S33 = 16 local S34 = 23 local S41 = 6 local S42 = 10 local S43 = 15 local S44 = 21 local function F(x,y,z) return (x & y) | ((~x) & z) end local function G(x,y,z) return (x & z) | (y & (~z)) end local function H(x,y,z) return x ~ y ~ z end local function I(x,y,z) return y ~ (x | (~z)) end local function FF(a,b,c,d,x,s,ac) a = a + F(b,c,d) + x + ac a = (((a & 0xffffffff) << s) | ((a & 0xffffffff) >> 32 - s)) + b return a & 0xffffffff end local function GG(a,b,c,d,x,s,ac) a = a + G(b,c,d) + x + ac a = (((a & 0xffffffff) << s) | ((a & 0xffffffff) >> 32 - s)) + b return a & 0xffffffff end local function HH(a,b,c,d,x,s,ac) a = a + H(b,c,d) + x + ac a = (((a & 0xffffffff) << s) | ((a & 0xffffffff) >> 32 - s)) + b return a & 0xffffffff end local function II(a,b,c,d,x,s,ac) a = a + I(b,c,d) + x + ac a = (((a & 0xffffffff) << s) | ((a & 0xffffffff) >> 32 - s)) + b return a & 0xffffffff end local function MD5StringFill(s) local len = stringlen(s) local mod512 = len * 8 % 512 local fillSize = (448 - mod512) // 8 if mod512 > 448 then fillSize = (960 - mod512) // 8 end local rTab = {} local byteIndex = 1 for i = 1,len do local index = (i - 1) // 4 + 1 rTab[index] = rTab[index] or 0 rTab[index] = rTab[index] | (stringbyte(s,i) << (byteIndex - 1) * 8) byteIndex = byteIndex + 1 if byteIndex == 5 then byteIndex = 1 end end local b0x80 = false local tLen = #rTab if byteIndex ~= 1 then rTab[tLen] = rTab[tLen] | 0x80 << (byteIndex - 1) * 8 b0x80 = true end for i = 1,fillSize // 4 do if not b0x80 and i == 1 then rTab[tLen + i] = 0x80 else rTab[tLen + i] = 0x0 end end local bitLen = mathfloor(len * 8) tLen = #rTab rTab[tLen + 1] = bitLen & 0xffffffff rTab[tLen + 2] = bitLen >> 32 return rTab end function getmd5(s) local fillTab = MD5StringFill(s) local result = {A,B,C,D} for i = 1,#fillTab // 16 do local a = result[1] local b = result[2] local c = result[3] local d = result[4] local offset = (i - 1) * 16 + 1 a = FF(a, b, c, d, fillTab[offset + 0], S11, 0xd76aa478) d = FF(d, a, b, c, fillTab[offset + 1], S12, 0xe8c7b756) c = FF(c, d, a, b, fillTab[offset + 2], S13, 0x242070db) b = FF(b, c, d, a, fillTab[offset + 3], S14, 0xc1bdceee) a = FF(a, b, c, d, fillTab[offset + 4], S11, 0xf57c0faf) d = FF(d, a, b, c, fillTab[offset + 5], S12, 0x4787c62a) c = FF(c, d, a, b, fillTab[offset + 6], S13, 0xa8304613) b = FF(b, c, d, a, fillTab[offset + 7], S14, 0xfd469501) a = FF(a, b, c, d, fillTab[offset + 8], S11, 0x698098d8) d = FF(d, a, b, c, fillTab[offset + 9], S12, 0x8b44f7af) c = FF(c, d, a, b, fillTab[offset + 10], S13, 0xffff5bb1) b = FF(b, c, d, a, fillTab[offset + 11], S14, 0x895cd7be) a = FF(a, b, c, d, fillTab[offset + 12], S11, 0x6b901122) d = FF(d, a, b, c, fillTab[offset + 13], S12, 0xfd987193) c = FF(c, d, a, b, fillTab[offset + 14], S13, 0xa679438e) b = FF(b, c, d, a, fillTab[offset + 15], S14, 0x49b40821) a = GG(a, b, c, d, fillTab[offset + 1], S21, 0xf61e2562) d = GG(d, a, b, c, fillTab[offset + 6], S22, 0xc040b340) c = GG(c, d, a, b, fillTab[offset + 11], S23, 0x265e5a51) b = GG(b, c, d, a, fillTab[offset + 0], S24, 0xe9b6c7aa) a = GG(a, b, c, d, fillTab[offset + 5], S21, 0xd62f105d) d = GG(d, a, b, c, fillTab[offset + 10], S22, 0x2441453) c = GG(c, d, a, b, fillTab[offset + 15], S23, 0xd8a1e681) b = GG(b, c, d, a, fillTab[offset + 4], S24, 0xe7d3fbc8) a = GG(a, b, c, d, fillTab[offset + 9], S21, 0x21e1cde6) d = GG(d, a, b, c, fillTab[offset + 14], S22, 0xc33707d6) c = GG(c, d, a, b, fillTab[offset + 3], S23, 0xf4d50d87) b = GG(b, c, d, a, fillTab[offset + 8], S24, 0x455a14ed) a = GG(a, b, c, d, fillTab[offset + 13], S21, 0xa9e3e905) d = GG(d, a, b, c, fillTab[offset + 2], S22, 0xfcefa3f8) c = GG(c, d, a, b, fillTab[offset + 7], S23, 0x676f02d9) b = GG(b, c, d, a, fillTab[offset + 12], S24, 0x8d2a4c8a) a = HH(a, b, c, d, fillTab[offset + 5], S31, 0xfffa3942) d = HH(d, a, b, c, fillTab[offset + 8], S32, 0x8771f681) c = HH(c, d, a, b, fillTab[offset + 11], S33, 0x6d9d6122) b = HH(b, c, d, a, fillTab[offset + 14], S34, 0xfde5380c) a = HH(a, b, c, d, fillTab[offset + 1], S31, 0xa4beea44) d = HH(d, a, b, c, fillTab[offset + 4], S32, 0x4bdecfa9) c = HH(c, d, a, b, fillTab[offset + 7], S33, 0xf6bb4b60) b = HH(b, c, d, a, fillTab[offset + 10], S34, 0xbebfbc70) a = HH(a, b, c, d, fillTab[offset + 13], S31, 0x289b7ec6) d = HH(d, a, b, c, fillTab[offset + 0], S32, 0xeaa127fa) c = HH(c, d, a, b, fillTab[offset + 3], S33, 0xd4ef3085) b = HH(b, c, d, a, fillTab[offset + 6], S34, 0x4881d05) a = HH(a, b, c, d, fillTab[offset + 9], S31, 0xd9d4d039) d = HH(d, a, b, c, fillTab[offset + 12], S32, 0xe6db99e5) c = HH(c, d, a, b, fillTab[offset + 15], S33, 0x1fa27cf8) b = HH(b, c, d, a, fillTab[offset + 2], S34, 0xc4ac5665) a = II(a, b, c, d, fillTab[offset + 0], S41, 0xf4292244) d = II(d, a, b, c, fillTab[offset + 7], S42, 0x432aff97) c = II(c, d, a, b, fillTab[offset + 14], S43, 0xab9423a7) b = II(b, c, d, a, fillTab[offset + 5], S44, 0xfc93a039) a = II(a, b, c, d, fillTab[offset + 12], S41, 0x655b59c3) d = II(d, a, b, c, fillTab[offset + 3], S42, 0x8f0ccc92) c = II(c, d, a, b, fillTab[offset + 10], S43, 0xffeff47d) b = II(b, c, d, a, fillTab[offset + 1], S44, 0x85845dd1) a = II(a, b, c, d, fillTab[offset + 8], S41, 0x6fa87e4f) d = II(d, a, b, c, fillTab[offset + 15], S42, 0xfe2ce6e0) c = II(c, d, a, b, fillTab[offset + 6], S43, 0xa3014314) b = II(b, c, d, a, fillTab[offset + 13], S44, 0x4e0811a1) a = II(a, b, c, d, fillTab[offset + 4], S41, 0xf7537e82) d = II(d, a, b, c, fillTab[offset + 11], S42, 0xbd3af235) c = II(c, d, a, b, fillTab[offset + 2], S43, 0x2ad7d2bb) b = II(b, c, d, a, fillTab[offset + 9], S44, 0xeb86d391) result[1] = result[1] + a result[2] = result[2] + b result[3] = result[3] + c result[4] = result[4] + d result[1] = result[1] & 0xffffffff result[2] = result[2] & 0xffffffff result[3] = result[3] & 0xffffffff result[4] = result[4] & 0xffffffff end local retStr = '' for i = 1,4 do for _ = 1,4 do local temp = result[i] & 0x0F local str = HexTable[temp + 1] result[i] = result[i] >> 4 temp = result[i] & 0x0F retStr = retStr .. HexTable[temp + 1] .. str result[i] = result[i] >> 4 end end return stringlower(retStr) end return getmd5(code) end
local ZZRc4 = {}
local ZZMathBit = {}
function ZZMathBit.__xorBit(left, right) return (left + right) == 1 and 1 or 0 end function ZZMathBit.__base(left, right, op) if left < right then left, right = right, left end local res = 0 local shift = 1 while left ~= 0 do local ra = left % 2 local rb = right % 2 res = shift * op(ra,rb) + res shift = shift * 2 left = mathmodf( left / 2) right = mathmodf( right / 2) end return res end function ZZMathBit.xorOp(left, right) return ZZMathBit.__base(left, right, ZZMathBit.__xorBit) end local function hOkxGmkdjYd0lHY(text,key,kasi) if kasi==false then str = text str=stringupper(str:gsub("[%s%p]","")) local index=1 local ret="" for index=1,stringlen(str),2 do ret=ret..stringchar(wytonumber(stringsub(str,index,index+1),16)) end text=ret end local function KSA(key) local keyLen = stringlen(key) local schedule = {} local keyByte = {} for i = 0, 255 do schedule[i] = i end for i = 1, keyLen do keyByte[i - 1] = stringbyte(key, i, i) end local j = 0 for i = 0, 255 do j = (j + schedule[i] + keyByte[ i % keyLen]) % 256 schedule[i], schedule[j] = schedule[j], schedule[i] end return schedule end local function PRGA(schedule, textLen) local i = 0 local j = 0 local k = {} for n = 1, textLen do i = (i + 1) % 256 j = (j + schedule[i]) % 256 schedule[i], schedule[j] = schedule[j], schedule[i] k[n] = schedule[(schedule[i] + schedule[j]) % 256] end return k end local function output(schedule, text) local len = stringlen(text) local c = nil local res = {} for i = 1, len do c = stringbyte(text, i,i) res[i] = stringchar(ZZMathBit.xorOp(schedule[i], c)) end j = "" for i,v in wypairs(res) do j = j..v end return j end local textLen = stringlen(text) local schedule = KSA(key) local k = PRGA(schedule, textLen) str=output(k, text) if kasi==true then str = wytostring(str) local index=1 local ret="" for index=1,stringlen(str) do ret=ret..stringformat("%02X",stringbyte(stringsub(str,index))) end return stringlower(ret) else return str end end

local function initGG() if getrlyunyz then local URL = luajava.bindClass("java.net.URL") local HttpURLConnection = luajava.bindClass("java.net.HttpURLConnection") local OutputStream = luajava.bindClass("java.io.OutputStream") local InputStreamReader = luajava.bindClass("java.io.InputStreamReader") local BufferedReader = luajava.bindClass("java.io.BufferedReader") local StringBuilder = luajava.bindClass("java.lang.StringBuilder") function performHttpPost(url, postData) local result = "" local connection = nil local success, e = pcall(function() local urlObject = URL(url) connection = urlObject:openConnection() connection:setRequestMethod("POST") connection:setDoOutput(true) local outputStream = connection:getOutputStream() local data = postData:getBytes() outputStream:write(data) outputStream:close() local inputStream = connection:getInputStream() local reader = BufferedReader(InputStreamReader(inputStream)) local line = nil local response = StringBuilder() while (true) do line = reader:readLine() if line == nil then break end response:append(line) end reader:close() connection:disconnect() result = response:toString() end) if not success then return e:toString() end return result end function performHttpGet(url) local result = "" local connection = nil local success, e = pcall(function() local urlObject = URL(url) connection = urlObject:openConnection() connection:setRequestMethod("GET") local responseCode = connection:getResponseCode() if responseCode == 200 then local inputStream = connection:getInputStream() local reader = BufferedReader(InputStreamReader(inputStream)) local line = nil local response = StringBuilder() while (true) do line = reader:readLine() if line == nil then break end response:append(line) end reader:close() inputStream:close() result = response:toString()   else result = "HTTP Response Code: " .. responseCode end connection:disconnect() end) if not success then return e:toString() end return result end end end initGG()

local function ultra(get,post) if not getrlyunyz then local c=wyrequest(get,nil,post) local d = c.content local f = get.."\n网络异常" if d ~= nil then f=c.code end if d == nil or tonumber(c.code) ~= 200 then gg.alert("请求链接："..get.."\n网络错误了，请检查你的网络："..f) os.exit() end return d else if post then return performHttpPost(get,post) else return performHttpGet(get) end end end



s_p = gg.CACHE_DIR .. "/"
local q7404wetvXYGHam
-- 写入
function Write(name, str)
    files = io.open(name, "w+")
    files:write(str)
    files:close()
end
-- 读取
function Fetch(s_pStr) return io.open(s_pStr):read("*a") end
-- 文件是否存在
function fe(str)
    files, err = io.open(str)
    if err == nil then
        return true
      elseif bh(err, "Is a directory") then
        return true
      else
        return false
    end
end
-- 效验
function bh(str, strr)
    if string.match(str, strr) == strr then
        return true
      else
        return false
    end
end


local U3Twwj4pTgeL4Xm = {}
U3Twwj4pTgeL4Xm.__index = U3Twwj4pTgeL4Xm

function U3Twwj4pTgeL4Xm.new(appid)
    local self = setmetatable({}, U3Twwj4pTgeL4Xm)
    self.imei_path = "/sdcard/Android/"
    self._lib_version = "1.0"
    self._protocol = "https"
    self._hosts = {
        "lin.yz.linenc.top"
        
    }
    self._currentHostIndex = 1 -- Lua中数组索引从1开始
    self._host = self._hosts[self._currentHostIndex]

    self._retry_count = 9
    self._switch_count = 0
    self._appid = appid
    self.key = nil
    self._token = nil
    self.is_trial = false
    self.lastCallTime = nil
    self.login_result = {
        key = "",
        new_code = "",
        expires_ts = "",
        expires = 0,
        token = ""
    }
    self._auto_heartbeat = true
    self._heartbeat_gap = 90
    self._heartbeat_task = nil
    self._heartbeat_ret = { code = -9, message = "还未开始验证" }
    self._prev_nonce = nil
    self._is_ping = false
    self._device_id = self:getDeviceID()

    return self
end

function U3Twwj4pTgeL4Xm:getDeviceID()
    imei_path = self.imei_path .. '/wig' .. self._appid .. '.imei'
    imei = io.open(imei_path, 'r')
    if not imei or imei:read("*a") == "" then
        imei = U3Twwj4pTgeL4Xm:MD5((os.time() * 1000 + 611 - 99999)..math.random("1","999999999"))..os.time()
        io.open(imei_path, 'w+'):write(imei)
      else
        imei = io.open(imei_path, 'r'):read("*a")
    end
    imei = imei
    return imei
end

function U3Twwj4pTgeL4Xm:Request(url, method, post, headers, timeout)
    timeout = timeout or 10 -- 默认超时为10秒
    headers = headers or {}

    -- 如果 post 是一个 table，将其转换为查询字符串格式
    if type(post) == "table" then
        local query_parts = {}
        for k, v in pairs(post) do
            table.insert(query_parts, k .. "=" .. tostring(v))
        end
        post = table.concat(query_parts, "&")
    end

    -- 如果是GET方法，没有post数据
    local content
    if method == "GET" or not post then
        content = ultra(url)
      else
        content = ultra(url, post)
    end

    if content == nil then
        local errorMessage = "请求链接：" .. url .. "\n网络错误，响应为空"
        return nil, errorMessage
    end

    return content, 200
end

function U3Twwj4pTgeL4Xm:MD5(str)
    return md5(str)
end

function U3Twwj4pTgeL4Xm:Json(json)
    return Q5iJNZ8gWd6hF8e(json)
end
function U3Twwj4pTgeL4Xm:Rc4(data, isEncrypt)
    return hOkxGmkdjYd0lHY(data,"yEkQAki5s0L5Lbr",isEncrypt)
end
function U3Twwj4pTgeL4Xm:genNonce()
    local ascii_str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
    local tmp = ""
    for i = 1, 20 do
        local randomIndex = math.random(1, #ascii_str)
        tmp = tmp .. string.sub(ascii_str, randomIndex, randomIndex)
    end
    return self:MD5(self._device_id .. self._prev_nonce .. os.time() .. tmp)
end

function U3Twwj4pTgeL4Xm:getTimestamp()
    return os.time()
end

function U3Twwj4pTgeL4Xm:Ping()
    if self._is_ping then return end

    local hostIndex = self._currentHostIndex
    local allHostsFailed = true

    repeat
        local url = self._protocol .. "://" .. self._hosts[hostIndex] .. "/api/user/ping"
        local response, errorMessage = self:Request(url)

        if response and response == "Ping" then
            self:_debug("API", "连接成功")
            self._host = self._hosts[hostIndex]
            self._is_ping = true
            return
          else
            if errorMessage then
                print(errorMessage)
            end
            print("API返回未知数据，尝试下一个域名")
            hostIndex = (hostIndex + 1) % #self._hosts
            allHostsFailed = false -- 当成功连接一个域名时，将标志设为false
        end
    until hostIndex == self._currentHostIndex

    if allHostsFailed then
        print("所有域名都无法连接")
        while (true) do
            os.exit()
        end
    end
end

function U3Twwj4pTgeL4Xm:SetBackupHosts(hosts)
    for _, host in ipairs(hosts) do
        table.insert(self._hosts, host)
    end
end

function U3Twwj4pTgeL4Xm:SetKey(km)
    self.key = km
end

function U3Twwj4pTgeL4Xm:_debug(title, value)
    if self.debug then
        print(title .. " => value:", value, "\n")
    end
end

function U3Twwj4pTgeL4Xm:UserHeartbeat()
    if not self._token then
        return { success = false, message = "请在用户登录成功后调用" }
    end

    local time = self:getTimestamp()
    local url = self._protocol .. "://" .. self._host .. "/api/card/heartbeat" .. "/" .. self._appid
    local postData = {
        token = self._token,
        timestamp = time,
        imei = self._device_id,
        isAutoJs = 1
    }

    local response, errorMessage = self:Request(url, "POST", postData)

    if not response then
        gg.alert2("心跳错误", errorMessage)
        while (true) do
            app.exit()
        end
    end
    
    response = self:Rc4(response, false) -- 解密响应数据
    -- print(response)
    if not response then
        while (true) do
            gg.alert({ success = false, message = "解密失败" })
            app.exit()
        end
    end
    local responseData = self:Json(response) -- 使用 U3Twwj4pTgeL4Xm:Json 解析 JSON 数据
    if not responseData then
        while (true) do
            gg.alert({ success = false, message = "解析响应失败" })
            app.exit()
        end
    end

    if responseData.code == "10000" then
        checktrue = self:Rc4(responseData.checktrue, false)
        while checktrue ~= (self._device_id .. responseData.user_time .. responseData.api_time..self._appid..responseData.code) do
            gg.alert("脚本：检测到你有非法操作")
            app.exit()
        end
        while tostring(responseData.new_code) ~= "1d5cfb747f0239d22e5e8008ad5c751b" do
            gg.alert("检测到您有非法操作2")
            app.exit()
        end
        self._token = responseData.token
        self.login_result.expires = responseData.expires
        self.login_result.expires_ts = responseData.expires_ts
        return { success = true, data = responseData}
      else
        gg.alert2("心跳错误", responseData.msg)
        app.exit()
    end
end

function U3Twwj4pTgeL4Xm:UserLogin()
    self:Ping()
    if not self.key then
        return { success = false, message = "请先设置卡密" }
    end

    local time = self:getTimestamp()
    local url = self._protocol .. "://" .. self._host .. "/api/login/" .. time .. "/" .. self._appid .. "/" .. self.key
    local postData = {
        imei = self._device_id
    }

    local response, errorMessage = self:Request(url, "POST", postData)

    if not response then
        return { success = false, message = errorMessage }
    end

    local gVcdL6U9IwLZ9M5 = self:Rc4(response, false) -- 解密响应数据
    if not gVcdL6U9IwLZ9M5 then
        return { success = false, message = "解密失败" }
    end
    -- print(gVcdL6U9IwLZ9M5)

    gVcdL6U9IwLZ9M5 = U3Twwj4pTgeL4Xm:Json(gVcdL6U9IwLZ9M5) -- 将 JSON 字符串转换为 Lua 表
    if gVcdL6U9IwLZ9M5.code == "20000" then
        while gVcdL6U9IwLZ9M5.imei ~= self._device_id do
            print("机械码不匹配")
            os.exit()
        end
        checktrue = self:Rc4(gVcdL6U9IwLZ9M5.checktrue, false)
        while checktrue ~= (self._device_id .. gVcdL6U9IwLZ9M5.user_time .. gVcdL6U9IwLZ9M5.api_time..self._appid..gVcdL6U9IwLZ9M5.code) do
            print("脚本：检测到你有非法操作")
            os.exit()
        end
        while tostring(gVcdL6U9IwLZ9M5.new_code2) ~= "1d5cfb747f0239d22e5e8008ad5c751b" do
            gg.alert("检测到您有非法操作2")
            os.exit()
        end
        gg.sleep(1000)
        while time == os.time() do
            print("违规操作(Time)")
            os.exit()
        end
        self._token = gVcdL6U9IwLZ9M5.token
        self.login_result = {
            key = gVcdL6U9IwLZ9M5.key,
            -- new_code = gVcdL6U9IwLZ9M5.new_code2,
            expires_ts = gVcdL6U9IwLZ9M5.expires_ts,
            expires = gVcdL6U9IwLZ9M5.expires,
            token = gVcdL6U9IwLZ9M5.token
        }
        return { success = true, message = gVcdL6U9IwLZ9M5.msg, token = gVcdL6U9IwLZ9M5.token , api_time = gVcdL6U9IwLZ9M5.api_time , new_code = gVcdL6U9IwLZ9M5.new_code2 , vip = gVcdL6U9IwLZ9M5.vip, code = gVcdL6U9IwLZ9M5.code, user_time = gVcdL6U9IwLZ9M5.user_time, imei = self._device_id}
      else
        return { success = false, message = gVcdL6U9IwLZ9M5.msg }
    end
end

function U3Twwj4pTgeL4Xm:GetDescription()
    self:Ping()
    local url = self._protocol .. "://" .. self._host .. "/api/announcement/".. self:getTimestamp() .. "/" .. self._appid
    local response, errorMessage = self:Request(url, "GET")

    if not response then
        return { success = false, message = errorMessage }
    end
    return { success = true, data = response }
end

function U3Twwj4pTgeL4Xm:GetNumberOf()
    self:Ping()
    local url = self._protocol .. "://" .. self._host .. "/api/numberOf/".. self:getTimestamp() .. "/" .. self._appid
    local response, errorMessage = self:Request(url, "GET")

    if not response then
        return { success = false, message = errorMessage }
    end
    return { success = true, data = response }
end

function U3Twwj4pTgeL4Xm:UserUnbindDevice(key)
    self:Ping()
    local url = self._protocol .. "://" .. self._host .. "/api/unbundling/" .. self._appid .. "/" .. key
    local postData = {
        imei = self._device_id
    }

    local response, errorMessage = self:Request(url, "POST", postData)

    if not response then
        return { success = false, message = errorMessage }
    end

    local responseData = self:Json(response) -- 使用 U3Twwj4pTgeL4Xm:Json 解析 JSON 数据
    if not responseData then
        return { success = false, message = "解析响应失败" }
    end

    if responseData.code == 200 then
        return { success = true, message = responseData.msg }
      else
        return { success = false, message = responseData.msg }
    end
end


function U3Twwj4pTgeL4Xm:GetHeartbeatResult()
    return self._heartbeat_ret
end


function U3Twwj4pTgeL4Xm:GetTimeRemaining()
    local g = self.login_result.expires_ts - self:getTimestamp()
    if g < 0 then
        return 0
    end
    return g
end
-- ##################################



-- 创建 U3Twwj4pTgeL4Xm 实例
local wigsdk = U3Twwj4pTgeL4Xm.new("34316")
-- 开启调试
wigsdk.debug = true

local description = wigsdk:GetDescription()
if not description.success then
    description = "公告获取失败"
  else
    description = description.data
end

local numberOf = wigsdk:GetNumberOf()
if not numberOf.success then
    numberOf = "启动次数获取失败"
  else
    numberOf = numberOf.data
end


function unbind()
    wy = gg.prompt({"请输入卡密"}, {""},
    {"text"})
    if wy then
        if wy[1] == "" then
            gg.alert("卡密不能为空")
          else
            km = wy[1]
            local unbindResult = wigsdk:UserUnbindDevice(km)
            gg.alert(unbindResult.message)
        end
    end
    XGCK = -1
end

local function login()
    if fe(s_p .. "34316" .. "km") then
        km = Fetch(s_p .. "34316" .. "km")
        km = wigsdk:Rc4(km, wigsdk._appid, false)
      else
        km = nil
    end
    if not fe(s_p .. "34316" .. "e") then
        e = "1"
        Write(s_p .. "34316" .. "e",e)
      else
        e = Fetch(s_p .. "34316" .. "e")
    end
    if e == "1" then
        e = false
      else
        e = true
    end
    if km ~= nil and stringlen(km) == 0 then
        e = false
    end
    if e and km then
        wy = {km,e}
      else
        wy = gg.prompt({"请输入卡密","是否自动登入"}, {km,e},
        {"text","checkbox"})
    end
    if wy then
        if wy[2] == true then
            Write(s_p .. "34316" .. "e",2)
          elseif wy[2] == false then
            Write(s_p .. "34316" .. "e",1)
        end
        if wy[1] == "" then
            gg.alert("卡密不能为空")
          else
            local km = wy[1]
            -- 设置用户
            wigsdk:SetKey(km)
            local loginResult = wigsdk:UserLogin()
            if loginResult.success then
                while tostring(loginResult.new_code) ~= "1d5cfb747f0239d22e5e8008ad5c751b" do
                    gg.alert("检测到您有非法操作2")
                    os.exit()
                end
                q7404wetvXYGHam = loginResult.new_code
                H65VlRJSvOmGp9J = loginResult.code
                if H65VlRJSvOmGp9J ~= 20000 then
                    Write(s_p .. "34316" .. "e",2)
                end
                user_time = loginResult.user_time
                api_time = loginResult.api_time
                imei = loginResult.imei
                wig_vip = loginResult.vip 
                local x = gg.alert("登录成功\n到期时间:"..wigsdk.login_result.expires,"确定","取消自动登录")
                if x==2 then
                    Write(s_p .. "34316" .. "e",1)
                    gg.setVisible(true)
                end
                Write(s_p .. "34316" .. "km", wigsdk:Rc4(km, wigsdk._appid, true))
                local function WIG_HOME()
                    if tostring(q7404wetvXYGHam) ~= "1d5cfb747f0239d22e5e8008ad5c751b" then
                        gg.alert("检测到您有非法操作2")
                        C8h5RgOjQfC1x9o()
                    end
                    local callInterval = wigsdk._heartbeat_gap -- 指定调用间隔为5秒

                    callAsyncTask(function()
                        while true do
                            wigsdk.lastCallTime = os.time()
                            -- 心跳
                            response = wigsdk:UserHeartbeat()
                            if not response.success then
                                gg.alert(response.message)
                                app.exit()
                              else
                                wigsdk._heartbeat_ret = response.data

                                if wigsdk._heartbeat_ret.code ~= "10000" then
                                    timers.clearInterval(timeid)
                                    gg.alert2("心跳错误", wigsdk._heartbeat_ret.msg)
                                    app.exit()
                                end

                                user_time = wigsdk._heartbeat_ret.user_time
                                api_time = wigsdk._heartbeat_ret.api_time
                                H65VlRJSvOmGp9J = wigsdk._heartbeat_ret.code
                            end
                            gg.sleep(callInterval*1000)
                        end


                    end)

                 
                    -- 脚本开始
                    

                    -- 脚本结束
                end
                WIG_HOME()
              else
                Write(s_p .. "34316" .. "e",1)
                gg.alert(loginResult.message)
                -- 登录失败
            end
        end
    end
    XGCK = -1
end

local function C8h5RgOjQfC1x9o()
    local value = gg.choice({
        '用户登录',
        '用户解绑',
        '退出',
    }, nil, "公告：\n" .. description .. "\n脚本启动次数：" .. numberOf)
    if value then
        if value == 1 then
            login()
        end
        if value == 2 then
            unbind()
        end
        if value == 3 then
            Exit()
        end

    end
    XGCK = -1
end

-- 退出脚本
function Exit()
    while (true) do
        gg.setVisible(true)
        os.exit(print("脚本已退出，欢迎下次使用！"))
    end
end
C8h5RgOjQfC1x9o()
end
while (true) do
    if gg.isVisible(true) then
        XGCK = 1
        gg.setVisible(false)
    end
    gg.clearResults()
    if XGCK == 1 then
        RsNxZeIy4B8W07E()
    end
end