OneStore是韩国第一大android应用市场,访问官网可能需要你科学上网才能正常访问。
[中文]OneStore开发工具
[中文]在Unity中使用ONE store In-App支付
国内手机可能不支持onestore,需要下载onestore的server和onestore的商店app
app:https://m.onestore.co.kr/mobilepoc/etc/marketDownloadGuide.omp
server:https://m.onestore.co.kr/mobilepoc/etc/downloadGuide.omp
Github onestore_iap_release
下载地址
插件导入目录

Assets > Plugins > Android
| 文件 | 详情 |
|---|---|
| AndroidManifest.xml | Project Settings > Player > Publishing Settings > Build |
| Iap_adapter-v1.3.0.aar | 负责Unity与ONE store In-App支付library的通信。 |
| Iap_sdk-v19.00.00.aar | ONE store In-App支付library文件 |
Assets > Scripts > Purchase
| 文件 | 详情 |
|---|---|
| AndroidNative.cs | 在Unity中启动安卓 AlertDialog的实用程序文件。 |
| GaaIapCallbackManager.cs | 负责从Unity调用Android发出的响应结果。 |
| GaaIapCallManager.cs | 负责在Unity中调用In-App支付SDK中的函数。 |
| GaaIapResultListener.cs | 接收来自GaaIapCallbackManager的响应结果,并加工数据以方便UI的写入。 |
| GaaPurchaseResponse.cs | In-App支付library中使用的Value Object定义的文件。 |
Assets > StreamingAssets
| 文件 | 详情 |
|---|---|
| global-appstores.json | 在In-App支付SDK中查找Payment module所需的文件。 |
初始化并连接ONE store In-App支付
请求In-App支付之前,您必须通过以下操作连接到ONE store服务。
当您尝试通过GaaIapCallManager.StartConnection()连接时,将在内部开始初始化SDK,并尝试与支付模块连接。此时,请参照global-appstores.json中定义的支付模块信息。
using Gaa
public class YourUiScript: MonoBehaviour
{
...
public void StartConnection()
{
if (GaaIapCallManager.IsServiceAvailable() == false)
{
GaaIapCallManager.StartConnection( /* your public key */ );
}
}
...
}
可以通过GaaIapResultListener.PurchaseClientStateEvent()获取有关确认连接响应的方法。
响应结果以GaaPurchaseResponse.IapResult对象的形式传递。
IapResult.code的值可通过GaaPurchaseResponse.ResponseCode查看。
void PurchaseClientStateEvent(IapResult iapResult)
{
if (iapResult.IsSuccess())
{
...
}
else if (iapResult.code == ResponseCode.RESULT_NEED_UPDATE)
{
...
}
else if (iapResult.code == ResponseCode.RESULT_NEED_LOGIN)
{
...
}
}
退出应用软件时,您必须断开与支付模块的连接。
void OnDestroy(
{
GaaIapCallManager.Destroy();
}
在开发者中心注册In-App商品时,生成的In-App商品ID用于查询In-App商品详情。如需查看In-App商品详情,请调用QueryProductDetails()。指定In-App商品ID(productId)数组的值及其对应的商品类型。
In-App商品类型包括管理型商品、包月型商品,如果想要同时查看这两种类型,只需输入ProductType.ALL即可。
为了查询App商品详细信息,应用软件使用在ONE store开发者中心配置商品时定义的In-App商品ID来查询。 有关更多信息,请参照开发人员中心。
可通过GaaIapResultListener的ProductDetailsSuccessEvent()和ProductDetailsErrorEvent()接收商品信息查询的响应结果值。
与Android和Unity的通信是字符串通信,由于一次传递的字符串长度有限,每次传递一个商品。
因此,ProductDetailsSuccessEvent(...,...,int count,int totalCount)值很重要。
Ex)1件商品:count=1,totalCount=1/10件商品:count=1,totalCount=10…。
Count=10,totalCount=10。
string[] all_products = { inapp_p5000, inapp_p10000, inapp_p50000, auto_a100000 };
GaaIapCallManager.QueryProductDetails(all_products, ProductType.ALL);
List<ProductDetail> products = new List<ProductDetail>();
void ProductDetailsSuccessEvent(ProductDetail productDetail, int count, int totalCount)
{
if (count == 1){
products.Clear();
}
products.Add(productDetail);
if (count == totalCount){
// send ProductDetail List to UI
}
}
void ProductDetailsErrorEvent(IapResult iapResult)
{
if (iapResult.code == ResponseCode.RESULT_NEED_UPDATE)
{
...
}
else if (iapResult.code == ResponseCode.RESULT_NEED_LOGIN)
{
...
}
}
In-App商品ID目录必须由应用软件自己的安全后端服务器管理。
要购买In-App商品,请调用GaaIapCallManager.LaunchPurchaseFlow()。
在调用时创建并指定GaaPurchaseResponse.PurchaseFlowParams对象。必需的值包括In-App商品ID(productId)和商品类型(管理型商品:ProductType.INAPP,包月型商品:ProductType.AUTO)。
此外,还放入开发商随机输入的developerPayload(最多200byte)。此值可用于在付款后检查数据的一致性和附加数据。
ProductName用于更改在支付时向用户展示的In-App商品的名称,而不是注册的In-App商品ID的名称。
ONE store为用户提供了折扣券、返现等优惠促销。
开发商可以使用gameUserId和promotionApplication值在购买请求时允许或限制使用app的用户参与促销。
开发商通过选择该应用软件的唯一用户识别号以及是否参与促销活动进行传递,而ONE store将根据这些值应用用户的促销优惠。
void BuyProduct(string productId, string type)
{
PurchaseFlowParams param = new PurchaseFlowParams();
param.productId = productId;
param.productType = type;
//param.productName = "";
//param.devPayload = "your Developer Payload";
//param.gameUserId = "";
//param.promotionApplicable = false;
GaaIapCallManager.LaunchPurchaseFlow(param);
}
调用LaunchPurchaseFlow()Method时,将显示ONE store的支付界面。
下图表示ONE store的支付界面。

支付的响应通过GaaIapResultListener的事件传递。
成功:PurchaseUpdatedSuccessEvent()
失败:PurchaseUpdatedErrorEvent()
由于“查询商品信息”等原因,count、totalCount都存在。
private List<PurchaseData> purchases = new List<PurchaseData>();
private List<string> signatures = new List<string>();
void PurchaseUpdatedSuccessEvent(PurchaseData purchaseData, string signature, int count, int totalCount)
{
if (purchaseData != null) {
if (count == 1){
purchases.Clear();
signatures.Clear();
}
purchases.Add(purchaseData);
signatures.Add(signature);
if (count == totalCount){
OnPurchaseUpdatedResponse(purchases, signatures);
}
}else{
// no PurchaseData
}
}
void PurchaseUpdatedErrorEvent(IapResult iapResult)
{
...
}
支付成功后,将创建一个唯一标识符“购买token”,即表示用户购买的购买ID。在应用软件中,您可以将购买token存储在本地,或者存储在安全后端服务器上,用于确认购买。
管理型商品的购买token对于每个购买ID都是唯一的,但包月型商品的购买token在更新期间保持不变。
用户还将通过电子邮件收到包含收据号码的交易收据。每次购买管理型商品时,您都会收到电子邮件,包月型产品在第一次购买时以及以后更新时都会收到电子邮件。
如果您使用的是ONE store IAP library v6或更高版本,则必须在3天内进行购买确认。如果无法确认购买,购买金额将退还。
您可以使用以下method之一确认购买:
对于消耗性产品,请使用 GaaIapCallManager.Consume()。
非消耗性产品,请使用 GaaIapCallManager.Acknowledge()。
对于包月型商品,只需确认首次支付的购买即可。
PurchaseData对象包含isAcknowledged()method,该method显示是否已确认购买。在确认购买之前,使用这些method,您可以确定您的购买是否已被确认。
下面是显示包月型商品的购买确认方法的示例。
void PurchaseUpdatedSuccessEvent(PurchaseData purchaseData, string signature, int count, int totalCount)
{
...
if (purchaseData != null) {
...
if (purchaseData.IsAcknowledged() == false)
{
GaaIapCallManager.Acknowledge(purchaseData, "your developer payload");
}
}
...
}
请求登录ONE store
ONE store In-App支付SDK必须登录后才能运行。
如果您以前登录过,ONE store会自动登录,但如果您需要登录,IapResult.code会在API请求中发送到ResponseCode.RESULT_NEED_LOGIN中。
传递RESULT_NEED_LOGIN后,必须调用GaaIapCallManager.LaunchLoginFlow()method。
响应的结果可通过GaaIapResultListener.LoginFlowEvent()查看。
下面是请求登录ONE store的示例。
GaaIapCallManager.LaunchLoginFlow();
void LoginFlowEvent(IapResult iapResult)
{
if (iapResult.IsSuccess()) {
// You need to specify the scenario after successful login.
}
}
安装ONE store服务
如果ONE store服务的版本较低或不存在,则不能使用In-App支付。
当尝试通过GaaIapCallManager.StartConnection()连接时,如果响应结果导致ResponseCode.RESULT_NEED_UPDATE,则需要调用GaaIapCallManager.LaunchUpdateOrInstallFlow()method。
响应的结果可通过GaaIapResultListener.UpdateOfInstallFlowEvent()查看。
以下是如何安装ONE store服务的示例。
GaaiapCallManager.LaunchUpdateOrInstallFlow();
void UpdateOrInstallFlowEvent(IapResult iapResult)
{
if (iapResult.IsSuccess()) {
// If the installation is completed successfully,
// you should try to reconnect with the ONE store service.
GaaIapCallManager.StartConnection("your public key")
} else {
...
}
}