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 | 支付商品 ID | string |
| 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 | 用户识别 ID | string |
| PackageName | 应用包名 | string |
| ProductID | 支付商品 ID | string |
| OrderID | 订单 ID | string |
| Currency | 支付货币代码 | string |
| Quantity | 购买数量 | integer |
| Price | 支付商品金额 | integer |
错误信息
收据验证失败的情况 ErrorCode : 20000 ErrorMessage : ValidationFailException
应用程序包名不匹配的情况 ErrorCode : 20002 ErrorMessage : NotMatchPackageNameException
收据已被使用的情况 ErrorCode : 20005 ErrorMessage : ExistsReceiptException