Version: 2017.3
Samsung Galaxy Apps
Unity IAP 小米集成指南

CloudMoolah MOO Store

CloudMoolah MOO Store 是一种让用户可以购买和销售移动应用程序的商业服务。它还为通过该应用商店发布的应用程序提供应用内购 (IAP) 服务。本指南介绍开发者向一个已发布到 CloudMoolah MOO Store 的游戏添加 IAP 服务的端到端过程。

MOO Store 服务于包括菲律宾、马来西亚、越南、新加坡和泰国在内的亚洲市场。用户拥有数字钱包,并可通过各种支付服务提供商(如移动支付、银行和便利店预付卡)向数字钱包充值。

Although compatible with Unity, the CloudMoolah MOO Store is not a Unity product. For more information, see Configuring for CloudMoolah MOO Store or the CloudMoolah Developer Portal website at dev.cloudmoolah.com.

将游戏发布到应用商店并将 IAP 添加到游戏中的一般工作流程如下所示:

  • 将游戏注册为 CloudMoolah Store 中的应用程序
  • 在应用商店中添加可以添加到游戏中供用户购买的商品
  • 将 CloudMoolah Store 初始化代码添加到游戏中
  • 测试集成结果
  • 将游戏发布到 CloudMoolah Store

准备开始

Your game must be built as an Android app. For information on building as an Android app, see Getting started with Android development.

要将游戏注册为 CloudMoolah Store 中的应用程序:

  1. Sign in to the CloudMoolah Developer Portal.

2.单击 App Listing

CloudMoolah Store 控制面板菜单
CloudMoolah Store 控制面板菜单

3.在 App Listing 页面上,单击 CREATE NEW APP 按钮。

CloudMoolah 的 Create New App 按钮
CloudMoolah 的 Create New App 按钮

4.在 App Detail 页面上,输入以下信息:

1.在 __App Name__ 中,输入在 CloudMoolah Store 中用于标识游戏的名称。

2.在 __BundelID__ 中,输入游戏在 Unity Editor 中使用的应用包名。

3.在 __Currency Name__ 中,输入玩家用于完成 IAP 的货币名称。

4. To create a HashKey that you will use in the initialization code for your app, click __GENERATE __next to the __HMAC/HashKey__ field.

5.在 __Notification HMAC__ 字段中,输入 App ID。在初始化期间将使用该值。

6.单击 __Save__。
CloudMoolah 创建新应用程序的结果
CloudMoolah 创建新应用程序的结果

添加用户可以购买的商品

IAP 是在应用程序内用金钱换取数字商品的交易。一个平台的应用商店会允许用户购买数字商品形式的产品。这些商品拥有一个标识符(通常是字符串数据类型)。

要在 CloudMoolah Developer Portal 中添加可购买的商品:

1.在 App Listing 页面上,单击 View IAP

CloudMoolah 的 View IAP 按钮
CloudMoolah 的 View IAP 按钮

2.在 IAP Listing 页面上,单击 CREATE NEW IAP 按钮。

CloudMoolah 的 Create New IAP 按钮
CloudMoolah 的 Create New IAP 按钮
  1. On the IAP Detail page, enter the following information:

    1. In the ProductID field, enter a string identifier that you will use in your code to enable purchase of the item in your game.

    2.在 Amount 字段中,使用您在注册游戏时指定的默认货币来输入商品的价格。

    3.在 Product Name 字段中,输入商品的名称。

    4.在 Product Description 中,输入商品的描述。

CloudMoolah 创建新 IAP 的结果
CloudMoolah 创建新 IAP 的结果

4.单击 SAVE

该商品现在显示在 IAP Listing 页面上,因此可以从游戏中引用它,从而将其提供给用户。

将 IAP 添加到游戏中

要在游戏中配置 IAP:

1.从 MOO Store Developer Portal 中检索应用程序商品的 appKey 和 hashKey,并保存好以便稍后使用。

发布到 CloudMoolah MOO Store 的应用程序必须先通过脚本 API 使用 IMoolahConfiguration 来配置 CloudMoolah appKey 和 hashKey,然后再初始化 Unity IAP。请从应用程序的 CloudMoolah 开发者控制面板 (Developer Dashboard) 中查找这些变量的值。

以下示例可配置并启动 Unity IAP 的初始化:

using UnityEngine.Purchasing; public class MyStore : IStoreListener { public void InitializeStore() { var module = StandardPurchasingModule.Instance(); var builder = ConfigurationBuilder.Instance(module);

        // Configure CloudMoolah
        builder.Configure<IMoolahConfiguration>().appKey = "d93f4564c41d463ed3d3cd207594ee1b";
        builder.Configure<IMoolahConfiguration>().hashKey = "cc";
        // For server-to-server (also called "online" games) transaction
        // logging, set IMoolahConfiguration.notificationURL.
        builder.Configure<IMoolahConfiguration>().notificationURL = "https://gameserver.example.com/callback";
        builder.Configure<IMoolahConfiguration>().SetMode(CloudMoolahMode.Production);
        // Add purchasable products. The product must be defined in the store.
        // Unity IAP provides the *ProductType* enumeration to specify the durability 
        // of a purchasable product. CloudMoolah limits the product type to Consumable. 
        builder.AddProduct("100.gold.coins", ProductType.Consumable);

        // Start asynchronous IAP initialization.
        UnityPurchasing.Initialize(this, builder);
    }
}
  1. In the Unity Editor, set the Unity IAP Android target to CloudMoolah by selecting Window > Unity IAP > Android > Target CloudMoolah. This sets CloudMoolah as the Android store that the game uses to fulfill IAP requests.
在 Editor 中启用 CloudMoolah
在 Editor 中启用 CloudMoolah

要在初始化代码中设置目标应用商店,请调用 UnityPurchasingEditor.TargetAndroidStore 函数:

UnityPurchasingEditor.TargetAndroidStore(AndroidStore.CloudMoolah);

1.为您的游戏生成经过签名的非开发版 Android APK。有关更多信息,请参阅 Android 开发入门 (Getting started with Android development)

注意:请采取特殊的预防措施来妥善保存密钥库文件。始终需要原始密钥库来更新已发布的应用程序。

For more information on setting up and configuring IAP, see Setting Up Unity IAP, Unity In-App Purchasing Initialization, and Integrating Unity In-App Purchasing with your game.

测试 IAP

CloudMoolah MOO Store 支持测试。要在 CloudMoolah MOO Store 中测试游戏,必须在购买之前调用 IMoolahConfiguration.SetMode 函数,从而在应用程序中启用开发者模式。

在游戏测试版本中设置测试模式时,交易是在虚拟的离线商店中处理的。这样允许您测试该应用程序的购买逻辑,而不会产生与商品相关的实际资金成本。

要修改游戏的 MOO Store 测试模式,请创建 ConfigurationBuilder 实例并添加以下行,然后编译并运行该应用程序来测试其 IAP 逻辑:

// 测试:自动批准所有交易
builder.Configure<IMoolahConfiguration>().SetMode(CloudMoolahMode.AlwaysSucceed);

要测试错误处理情况,请配置测试模式使所有交易失败。为此,请使用 CloudMoolahMode.AlwaysFailed 枚举:

builder.Configure<IMoolahConfiguration>().SetMode(CloudMoolahMode.AlwaysFailed); // 测试:始终让所有交易失败

注意:完成测试后,请删除用于配置开发者模式的 SetMode 语句,或更改该参数以使用 CloudMoolahMode.Production 枚举值。这样可确保在用户使用应用程序时支付实际资金。

实现示例

Unity IAP 的默认集成中包括一个实现脚本示例,其中演示了如何使用必需的和一些可选的 CloudMoolah 脚本 API。

要查看特定于 CloudMoolah 的示例:

1.在您的开发计算机上,打开已启用 IAP 的应用程序的文件夹。

2.打开 Assets/Plugins/UnityPurchasing/script 文件夹。

3.在 script 文件夹中,打开 IAPDemo.cs

该示例实现了 Awake 函数,而此函数调用 IMoolahConfiguration API 来设置 appKeyhashKey。这会将应用程序连接到 CloudMoolah Store 服务器。

The IAPDemo.cs file also shows how to use optional API calls to configure test mode, and for extending functionality to include transaction restoration. For more information on the optional APIs, sign in to the CloudMoolah Developer Portal website at dev.cloudmoolah.com.


2018–03–07 页面已修订并只进行了有限的编辑审查

Samsung Galaxy Apps
Unity IAP 小米集成指南