AptoideBillingSDKManager
AptoideBillingSDKManager 是在 Unity 应用中处理应用内计费操作的主接口。它简化了诸如查询购买、获取商品详情、消耗购买项、确认非消耗型购买、管理用户的 Aptoide 账户登录以及管理计费流程等操作。此外,它还提供用于应用更新和推荐深度链接的实用工具。
若要使用 AptoideBillingSDKManager,请通过 InitializePlugin 方法进行初始化,并传入所需的监听器、公钥和类名。该 SDK 通过管理与底层 Android 桥接层的连接,确保与 Aptoide 计费系统的无缝集成。
公共方法
InitializePlugin
static void InitializePlugin(IAptoideBillingClientStateListener aptoideBillingClientStateListener, IConsumeResponseListener consumeResponseListener, IPurchasesUpdatedListener purchasesUpdatedListener, IPurchasesResponseListener purchasesResponseListener, IProductDetailsResponseListener productDetailsResponseListener, IAcknowledgeResponseListener acknowledgeResponseListener, IAptoideSignInResponseListener aptoideSignInResponseListener, IAptoideAccountStateListener aptoideAccountStateListener, string publicKey, string className)
使用所需的监听器和配置初始化插件。
参数
| 名称 | 类型 | 说明 |
|---|---|---|
| aptoideBillingClientStateListener | IAptoideBillingClientStateListener | 计费状态变更的监听器。 |
| consumeResponseListener | IConsumeResponseListener | 消耗响应的监听器。 |
| purchasesUpdatedListener | IPurchasesUpdatedListener | 购买更新的监听器。 |
| purchasesResponseListener | IPurchasesResponseListener | 购买查询响应的监听器。 |
| productDetailsResponseListener | IProductDetailsResponseListener | 商品详情响应的监听器。 |
| acknowledgeResponseListener | IAcknowledgeResponseListener | 确认响应的监听器。 |
| aptoideSignInResponseListener | IAptoideSignInResponseListener | Aptoide 账户登录结果的监听器。 |
| aptoideAccountStateListener | IAptoideAccountStateListener | Aptoide 账户登录状态变更的监听器。 |
| publicKey | String | 用于验证购买的公钥。 |
| className | String | 与计费 SDK 桥接层关联的类名。 |
Initialize
static void Initialize(string publicKey, string className)
使用提供的公钥和类名初始化 Android 桥接层。
StartConnection
static void StartConnection()
启动与计费系统的连接。
EndConnection
static void EndConnection()
结束与计费系统的连接,并释放资源。
IsReady
static bool IsReady()
检查计费系统是否已准备好执行操作。
返回值
指示系统是否就绪的 Boolean 值。
QueryProductDetailsAsync
static void QueryProductDetailsAsync(QueryProductDetailsParams queryProductDetailsParams)
异步获取指定商品 ID 的商品详情。
参数
| 名称 | 类型 | 说明 |
|---|---|---|
| queryProductDetailsParams | QueryProductDetailsParams | 待查询购买项的参数。 |
LaunchBillingFlow
static BillingResult LaunchBillingFlow(BillingFlowParams billingFlowParams)
为指定的 SKU 启动计费流程。
参数
| 名称 | 类型 | 说明 |
|---|---|---|
| billingFlowParams | BillingFlowParams | 计费流程的参数。 |
返回值
所收到响应的 BillingResult 类型的计费结果。
ConsumeAsync
static void ConsumeAsync(ConsumeParams consumeParams)
消耗先前购买的商品。
参数
| 名称 | 类型 | 说明 |
|---|---|---|
| consumeParams | ConsumeParams | 待消耗购买项的参数。 |
AcknowledgeAsync
static void AcknowledgeAsync(AcknowledgeParams acknowledgeParams)
确认购买,在保持其归属的同时完成交易。对于一次性非消耗型商品,请使用此方法而非 ConsumeAsync,以便购买不会被退款,并继续由 QueryPurchasesAsync 返回。结果将传递给 IAcknowledgeResponseListener。
此功能通过远程开关控制。请使用 IsFeatureSupported(4) 验证其可用性(响应码为 0 表示已启用)。
参数
| 名称 | 类型 | 说明 |
|---|---|---|
| acknowledgeParams | AcknowledgeParams | 待确认购买项的参数。 |
IsFeatureSupported
static BillingResult IsFeatureSupported(int feature)
检查特定功能是否受支持。
参数
| 名称 | 类型 | 说明 |
|---|---|---|
| feature | int | 待检查功能的值。 |
返回值
所收到响应的 BillingResult 类型的计费结果。
QueryPurchasesAsync
static void QueryPurchasesAsync(QueryPurchasesParams queryPurchasesParams)
根据指定的 QueryPurchasesParams异步获取与用户关联的购买项,并返回给 iPurchasesResponseListener。
参数
| 名称 | 类型 | 说明 |
|---|---|---|
| queryPurchasesParams | QueryPurchasesParams | 待查询购买项的参数。 |
SignInToAptoideServices
static void SignInToAptoideServices()
在 WebView 中启动 Aptoide 账户登录流程。登录后,用户的购买项会与其 Aptoide 账户关联,从而使待处理购买项和非消耗型购买项在重新安装和跨设备时都可通过 QueryPurchasesAsync 获取。结果将传递给 IAptoideSignInResponseListener。
此功能通过远程开关控制。请使用 IsFeatureSupported(3) 验证其可用性(响应码为 0 表示已启用)。
SignOutFromAptoideServices
static void SignOutFromAptoideServices()
将用户从其 Aptoide 账户中登出,清除已存储的会话,并将后续所有操作恢复为匿名访客流程。任何已注册的 IAptoideAccountStateListener 都会收到状态 0(已登出)的通知。
IsSignedInToAptoideServices
static bool IsSignedInToAptoideServices()
检查用户当前是否已登录其 Aptoide 账户。
返回值
指示用户是否已登录的 Boolean 值。
GetReferralDeeplink
static ReferralDeeplinkResult GetReferralDeeplink()
获取与应用关联的推荐深度链接。
返回值
包含深度链接详情的 ReferralDeeplinkResult。
IsAppUpdateAvailable
static bool IsAppUpdateAvailable()
检查是否有可用的应用更新。
返回值
指示是否有可用更新的 Boolean 值。
LaunchAppUpdateDialog
static void LaunchAppUpdateDialog()
显示提示用户更新应用的对话框。
LaunchAppUpdateStore
static void LaunchAppUpdateStore()
打开用于更新应用的商店页面。
回调处理程序
以下回调方法用于处理来自 Android 桥接层的响应:
- BillingSetupFinishedCallback:在计费设置完成时调用。
- BillingServiceDisconnectedCallback:在计费服务断开连接时调用。
- PurchasesUpdatedCallback:处理购买项的更新。
- PurchasesResponseCallback:处理购买查询结果。
- ProductDetailsResponseCallback:处理商品详情的响应。
- ConsumeResponseCallback:处理消耗操作的响应。
- AcknowledgeResponseCallback:处理确认操作的响应。
- SignInResponseCallback:处理 Aptoide 账户登录的结果。
- AccountStateChangedCallback:处理 Aptoide 账户登录状态的变更。