【问题标题】:Dynamic In-App Purchases动态应用内购买
【发布时间】:2014-12-15 21:21:26
【问题描述】:

这个问题 (Android In-App Billing Dynamic Product List) 是 3 年前提出的。 Android 仍然无法使用动态应用内购买项目吗?

我希望实现此类功能的原因是因为我的应用程序为某些用户提供了一种方式来创建自己的应用程序内购买以供其他人购买。

似乎另一种解决方案是使用可消耗的应用内货币,但我更愿意直接通过 Play 商店购买(特别是因为我已经看到到处破解游戏内货币的方法)。

无论选项如何,我都想使用服务器端验证。有没有办法通过服务器添加应用内购买?

【问题讨论】:

    标签: android in-app-purchase google-play google-play-services


    【解决方案1】:

    我不确定这是否足够,但您可以通过这种方式使用 Google Play APIinsert 新的应用计费产品。所有适用于 Android 的应用内计费产品仍需要在 Google Play 开发者控制台中输入 specified,但至少使用 Play API,您可以通过编程方式完成。

    【讨论】:

    • 这看起来很有希望!我会在问题实施后立即更新。谢谢
    • 嗨@Andy,你能告诉我如何使用 API 使用这个插入产品的细节吗?我在这个文档中无法理解如何动态插入我的项目。
    • 我遇到了同样的问题,你能帮帮我吗,或者你有什么例子。 @nidhi c0deblooded
    • @c0deblooded 你实现了这个功能吗?:)
    • @JarsOfJam-Scheduler 不,我没有最终将这个逻辑添加到我的应用程序中,因为我不久之后就调整了设计。不过,如果将来需要,这绝对是可行的。
    【解决方案2】:

    我设法使用 Google Play Api 实现了这一点,并以动态/编程方式将产品上传到 Playstore。

    首先我使用 PHP,因为我将 Laravel 用于我的后端 REST API。由您自己选择。我将使用 composer 安装 google/apiclient 库 使用composer require google/apiclient

    https://developers.google.com/android-publisher/api-ref/inappproducts

    https://developers.google.com/android-publisher/api-ref/inappproducts/insert

    可以这样上传示例产品:

    第 1 步:您需要对服务进行身份验证。如果您愿意,可以使用服务 json 文件或 Auth oath。就我而言,我使用了服务 json 文件并在我的 GCP 控制台中启用了 Google Play API。

    第 2 步:您需要一个 sku(唯一)参考文档并查看所需格式

    步骤 3: 您需要设置一个价格(微),您可以使用 https://github.com/Torann/laravel-currency 将一种货币转换为另一种货币商店(应用内产品)注意:货币必须匹配,否则会出错。

    第 4 步:您需要设置列表,这些列表基本上是您的应用出于翻译目的所需的标题/描述

    
    $client = new Google_Client();
    $client->setAuthConfig(storage_path('service_account.json'));
    
    // You have to add this scope so it knows it is in app billing store
    $client->addScope('https://www.googleapis.com/auth/androidpublisher');
    $service = new Google_Service_AndroidPublisher($client);
    
    $body = new \Google_Service_AndroidPublisher_InAppProduct();
    $body->setSku("unique_sku_here");
    $body->setPackageName('android_app_package_name'); // e.g com.example.in_app_test
    
    //1.00 USD = 1,000,000 Microns.
    
    // Create a new price object 
    $price = new \Google_Service_AndroidPublisher_Price();
    $price->setCurrency('USD');
    
    //Using **torann/currency** library to convert from one currency to another
    
    $new_price = intval(currency("1000", $from = "EUR", $to = "USD", false));
    $price->priceMicros = $new_price * 1000000;
    $body->setDefaultPrice($price);
    
    // Setting the default language
    
    $body->defaultLanguage = "en_US";
    $body->setListings([
                        'en_US' => [
                            'title' => 'Product Title',
                            'description' => "Product Description here"
                        ]
                    ]);    
    
    $purchase = $service->inappproducts->insert(
                         'android_app_package_name',
                         $body,
                        [
                          'autoConvertMissingPrices' => true,
                        ]);
    
    $purchase->setStatus(true); // Always set this to mark the product active on the GPlay console.
    

    这样您将获得成功上传产品的回报。

    干杯。如果您有任何障碍,请随时发表评论,我很乐意澄清。

    【讨论】:

    • 嗨,我已经在我的 Java 后端使用这个 API 成功地将产品插入到 Play 商店(它是活动的和可见的),但是只有我通过这个 API 添加的产品不会加载到客户端当我尝试使用 Google Play 计费库查询我的产品时。我通过控制台手动添加的产品只可见,这很奇怪。你碰巧知道为什么吗?您是否也遇到过类似的问题?
    • 我能看看你们是怎么拿到这些产品的吗?
    • 您好,这里是reference,提供更多详细信息。
    猜你喜欢
    • 1970-01-01
    • 2020-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多