简体   繁体   English

Google In App Billing 区分用户帐户

[英]Google In App Billing differentiate user accounts

I'm developing an app that contains In App Billing non consumable product (Life time Subscription).我正在开发一个包含 In App Billing 非消耗性产品(终身订阅)的应用程序。
User has one email associated with Play Store on his device.用户在他的设备上有一个与 Play Store 关联的 email。

Scenario:设想:
User A create new account using user1@test.com and purchase Lifetime Subscription and logout.用户 A 使用 user1@test.com 创建新帐户并购买终身订阅并注销。
User B create new account using user2@test.com and trying to purchase.用户 B 使用 user2@test.com 创建新帐户并尝试购买。
but he get response BillingClient.BillingResponse.ITEM_ALREADY_OWNED .但他得到了回应BillingClient.BillingResponse.ITEM_ALREADY_OWNED

How do i differ each user to buy item?我如何区分每个用户购买商品?
I'm using 'com.android.billingclient:billing:2.2.1'我正在使用'com.android.billingclient:billing:2.2.1'

If you are using Firebase authentication then you can get user's unique id using String uid = FirebaseAuth.getInstance().getCurrentUser().getUid() and you can use this Id at the time of purchase like -如果您使用的是 Firebase 身份验证,那么您可以使用String uid = FirebaseAuth.getInstance().getCurrentUser().getUid()获取用户的唯一 ID,并且您可以在购买时使用此 ID,例如 -

BillingFlowParams billingFlowParams = BillingFlowParams.newBuilder()
                .setSkuDetails(skuDetails).setObfuscatedAccountId(uid)
                .build();
        BillingResult billingResult = billingClient.launchBillingFlow(activity, billingFlowParams);

Also in your database use this as unique identifier to check whether user has the subscriotion or not.同样在您的数据库中使用它作为唯一标识符来检查用户是否有订阅。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM