c0d*_*ded 6 android in-app-purchase google-play google-play-services
这个问题(Android In-App Billing Dynamic Product List)是在 3 年前提出的。Android 仍然无法使用动态应用内购买项目吗?
我希望实现这种功能的原因是我的应用程序为某些用户提供了一种方式来创建他们自己的应用程序内购买供其他人购买。
似乎另一种解决方案是使用可消耗的应用内货币,但我更愿意直接通过 Play 商店购买(尤其是因为我已经看到了到处都可以破解游戏内货币的方法)。
无论选项如何,我都想使用服务器端验证。有没有办法通过服务器添加应用内购买?
小智 6
我设法使用 Google Play Api 来实现这一点,并以动态/编程方式将产品上传到 Playstore。
首先我使用 PHP,因为我使用 Laravel 作为后端 REST API。由您自己选择。我将google/apiclient使用 Composer 安装该库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 誓言。就我而言,我使用了服务 json 文件并在 GCP 控制台中启用了 Google Play API。
第2步:您需要一个sku(唯一),请参阅文档并查看所需的格式
步骤3:您需要设置一个价格(微单位),您可以使用https://github.com/Torann/laravel-currency从一种货币转换为另一种货币,我在本例中使用它来根据默认货币获取我的货币商店(在应用程序产品中)注意:货币必须匹配,否则您将收到错误消息。
第四步:您需要设置列表,这些列表基本上是您的应用程序出于翻译目的所需的标题/描述
$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.
Run Code Online (Sandbox Code Playgroud)
这样您将获得产品上传成功的结果。
干杯。如果您有任何阻碍,请随时发表评论,我很乐意澄清。
我不确定这是否足够,但您可以使用Google Play API并通过这种方式在应用结算产品中插入新产品。所有适用于 Android 的应用内计费产品仍然需要在 Google Play Developer Console 中指定,但至少使用 Play API,您可以通过编程方式来完成。
| 归档时间: |
|
| 查看次数: |
3349 次 |
| 最近记录: |