licensing.*

类型 CoronaLibrary
修订版本 版本 2024.3703
关键词 许可证,许可

概述

Solar2D 许可库允许您检查应用程序是否是从商店购买的。目前,仅支持 Google Play

更多信息,请参阅 Google 许可 参考页面。

项目设置

您必须将以下权限添加到您的 build.settings 文件中才能使用 Google 许可提供程序

settings =
{
    android =
    {
        usesPermissions =
        {
            "com.android.vending.CHECK_LICENSE"
        },
    },
}

此外,您必须在项目的 config.lua 文件中包含带有您唯一许可证密钥的 license 表。此密钥值必须从 Google 获取。

application =
{
    license =
    {
        google =
        {
            key = "YOUR_LICENSE_KEY",
            policy = "serverManaged"
        },
    },
}
注意

policy 键是可选的。其值可以是 "serverManaged"(默认)或 "strict"。值为 "serverManaged" 将查询 Google 服务器并缓存结果;这类似于 Google 的**服务器托管策略**。值为 "strict" 将不会缓存结果,因此当网络出现故障时,许可将失败;这类似于 Google 的**严格策略**。

函数

licensing.init()

licensing.verify()

示例

local licensing = require( "licensing" )

local function licensingListener( event )

    if not ( event.isVerified ) then
        -- Failed to verify app from the Google Play store; print a message
        print( "Pirates!!!" )
    end
end

local licensingInit = licensing.init( "google" )

if ( licensingInit == true ) then
    licensing.verify( licensingListener )
end