Android 结算如何使用 setAccountId 或将付款分配给自定义标识符

Android Billing how to use setAccountId or assign payment to custom identifier

我想**允许我的用户在多个设备上使用我的应用程序**。用户必须通过 firebase 身份验证登录我的应用程序。

问题是 付款分配给在设备上登录的帐户(google 播放),而不是登录到应用程序的帐户。** 来自 firebase auth 我可以获得我的应用程序用户的电子邮件地址 - 这可以用作一些唯一标识符。

可视化问题:

我注意到在 Billing flow 中有 .setAccountId("some id") 我想我可以用它来填写用户的唯一标识符。但是如何使用它查询购买?

BillingFlowParams.Builder builder = new BillingFlowParams.Builder()
                .setAccountId("some id")
                .setSku(PREMIUM_YEAR_SUBS).setType(BillingClient.SkuType.SUBS);

TLDR:我只想检索与我的 APP 用户帐户关联的购买, not 设备帐户 (google 播放当前登录的用户)

要使用 accountId 实现计费,请尝试使用 getBuyIntentExtraParams() 方法,与 getBuyIntent() 方法相比,它提供了更多功能。

使用此方法,您可以使用 accountId 并附上以下说明:

Optional obfuscated string that is uniquely associated with the user's account in your app. If you pass this value, Google Play can use it to detect irregular activity, such as many devices making purchases on the same account in a short period of time.

此外,您可能还想通过 API 讨论的应用内结算检查典型的购买流程 here

好像获取不到accountId,刚玩google用的accountId。 我猜你使用的是 accountId 而不是 payload,但经过我的尝试,我认为它没有成功。 在 Google 计费库中,删除了开发负载以获得 in-app-purchase 和 out-app-purchase 之间的相同体验。虽然我们可以在consume或者acknowledge的时候加上payload,但是没用。并且payload应该是在购买的时候设置的,但是google删除了,不会加回来。 The payload issues.

您可以检查附加到每个 PurchaseAccountId 使用 Purchase.getAccountIdentifiers

它将 return AccountIdentifiers 对象具有 AccountIdProfileId 之前在 BillingFlowParams 启动计费流程时设置的

之后,您可以将当前用户帐户 ID 与每次购买时附带的帐户 ID 进行比较 检测连接到当前用户帐户的购买