範例

-- 簡單的付費選單驗證範例 -- 依賴 MachoAuthenticationKey 與 MachoWebRequest

-- 驗證伺服器網址(需自行架設) local AUTH_SERVER = "https://myserver.com/validate?key="

-- 驗證函式 function AuthenticateUser() -- 取得當前使用者金鑰 local key = MachoAuthenticationKey() print("[Auth] 當前使用者金鑰: " .. key)

-- 發送到驗證伺服器
local response = MachoWebRequest(AUTH_SERVER .. key)

-- 根據伺服器回傳值決定行為
if response == "VALID" then
    print("[Auth] 驗證成功!允許使用選單。")
    LoadMenu()
elseif response == "EXPIRED" then
    print("[Auth] 金鑰已過期,請重新購買授權。")
else
    print("[Auth] 驗證失敗,拒絕訪問。")
end

end

-- 模擬載入選單 function LoadMenu() local win = MachoMenuWindow(0.2, 0.2, 0.5, 0.5) local group = MachoMenuGroup(win, "Main Section", 0.01, 0.01, 0.49, 0.49)

MachoMenuButton(group, "Say Hello", function()
    print("Hello, this is a paid menu feature!")
end)

MachoMenuText(group, "驗證通過後才能看到這些內容")

end

-- 腳本啟動時呼叫 AuthenticateUser()

⚙️ 範例流程解說

  1. 取得金鑰

    local key = MachoAuthenticationKey()

    → 這是 Macho 內建 API,會回傳使用者目前使用的金鑰。

  2. 發送驗證請求

    local response = MachoWebRequest(AUTH_SERVER .. key)

    → 把金鑰丟到你的伺服器,伺服器會回應 "VALID", "EXPIRED", "INVALID" 等字串。

  3. 決定是否載入功能

    • VALID → 呼叫 LoadMenu() 顯示付費選單

    • EXPIRED → 提示金鑰過期

    • 其他 → 驗證失敗,拒絕載入

最后更新于