[英]Dynamic In-App Purchases
这个问题( Android In-App Billing Dynamic Product List )是在 3 年前提出的。 Android 仍然无法使用动态应用内购买项目吗?
我希望实现这种功能的原因是因为我的应用程序为某些用户提供了一种方式来创建他们自己的应用程序内购买供其他人购买。
似乎另一种解决方案是使用可消耗的应用内货币,但我更愿意直接通过 Play 商店购买(尤其是因为我已经看到了到处都可以破解游戏内货币的方法)。
无论选项如何,我都想使用服务器端验证。 有没有办法通过服务器添加应用内购买?
我不确定这是否足够,但您可以使用Google Play API并通过这种方式在应用结算产品中插入新产品。 Android 的所有应用内计费产品仍然需要在 Google Play Developer Console 中指定,但至少使用 Play API,您可以通过编程方式来完成。
我设法使用 Google Play Api 并以动态/编程方式将产品上传到 Playstore 来实现这一点。
首先我使用 PHP,因为我将 Laravel 用于我的后端 REST API。 由您来选择自己的。 我将使用composer require google/apiclient
使用composer require google/apiclient
安装google/apiclient
库
https://developers.google.com/android-publisher/api-ref/inappproducts
https://developers.google.com/android-publisher/api-ref/inappproducts/insert
样品产品可以这样上传:
步骤 1:您需要对服务进行身份验证。 如果您愿意,可以使用服务 json 文件或 Auth 誓言。 就我而言,我使用了服务 json 文件并在我的 GCP 控制台中启用了 Google Play API。
步骤 2:您需要一个 sku(唯一),请参阅文档并查看所需的格式
第3步:您需要设置一个价格(micros),您可以使用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.
有了这个,您将获得成功上传产品的回报。
干杯。 如果您有任何阻碍,请随时发表评论,我很乐意澄清。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.