跳转到主要内容

iOS 收据验证

验证 iOS 应用内购买的收据信息。

调用信息

IAP.IOS(string receipt, string productId, string currency, double price, PlayNANOODelegate callback) {}
IAP.IOS(string receipt, string productId, string currency, double price, bool duplicateAllow, PlayNANOODelegate callback) {}

调用详细信息

参数说明类型
receipt收据信息string
productId支付商品 IDstring
currency货币代码 (KRW, JPY, USD, CNY...)string
price支付金额double
duplicateAllow是否允许重复收据验证boolean
callback通信结果PlayNANOODelegate

示例

使用 Unity IAP 服务的情况

using PlayNANOO;

public class PlayNANOOExample : MonoBehaviour
{
Plugin plugin;

void Awake()
{
plugin = Plugin.GetInstance();
}

// Unity IAP Service
public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
{
plugin.IAP.IOS(args.purchasedProduct.receipt, "PRODUCT_ID", "CURRENCY", 100, (status, errorMessage, jsonString, values) => {
if (status.Equals(Configure.PN_API_STATE_SUCCESS))
{
Debug.Log(values["UserID"]);
Debug.Log(values["PackageName"]);
Debug.Log(values["OrderID"]);
Debug.Log(values["ProductID"]);
Debug.Log(values["Currency"]);
Debug.Log(values["Quantity"]);
Debug.Log(values["Price"]);
}
else
{
Debug.Log("Fail");
}
});
}
}

不使用 Unity IAP 服务的情况

using PlayNANOO;

public class PlayNANOOExample : MonoBehaviour
{
Plugin plugin;

void Awake()
{
plugin = Plugin.GetInstance();

plugin.IAP.IOS("RECEIPT", "PRODUCT_ID", "CURRENCY", 100, (status, errorMessage, jsonString, values) => {
if (status.Equals(Configure.PN_API_STATE_SUCCESS))
{
Debug.Log(values["UserID"]);
Debug.Log(values["PackageName"]);
Debug.Log(values["OrderID"]);
Debug.Log(values["ProductID"]);
Debug.Log(values["Currency"]);
Debug.Log(values["Quantity"]);
Debug.Log(values["Price"]);
}
else
{
Debug.Log("Fail");
}
});
}
}

通信结果

HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
{
"UserID" : "String",
"PackageName" : "String",
"OrderID" : "String",
"ProductID" : "String",
"Currency" : "String",
"Price" : "String"
}

通信结果详细信息

数据键说明类型
UserID用户识别 IDstring
PackageName应用包名string
ProductID支付商品 IDstring
OrderID订单 IDstring
Currency支付货币代码string
Quantity购买数量integer
Price支付商品金额integer

错误信息

收据验证失败的情况 ErrorCode : 20000 ErrorMessage : ValidationFailException

应用程序包名不匹配的情况 ErrorCode : 20002 ErrorMessage : NotMatchPackageNameException

收据已被使用的情况 ErrorCode : 20005 ErrorMessage : ExistsReceiptException