iOS 收据验证
用于验证 iOS 应用内购买(IAP)收据的 API。
URL 确认
此 API 使用 service-api.playnanoo.com 域名。
API 信息
- URL:
https://service-api.playnanoo.com/iap/v20221001/unity/ios - Method:
PUT - 需要认证: 是
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| receipt | string | 必填 | 收据信息 |
| product_id | string | 必填 | 支付商品 ID |
| currency | string | 必填 | 货币代码 (KRW, JPY, USD, CNY...) |
| price | string | 必填 | 支付金额 |
| duplicate_allow | string | 必填 | 是否允许重复验证收据 (Y/N) |
响应数据
Res 类
| 字段 | 类型 | 说明 |
|---|---|---|
| UserID | string | 用户 ID |
| PackageName | string | 包名 |
| OrderID | string | 订单 ID |
| ProductID | string | 商品 ID |
| Currency | string | 货币代码 |
| Price | string | 价格 |
Unity C# 实现
BaseResponse 类
所有 API 响应的基类。
public class BaseResponse
{
public string ErrorCode;
public string Message;
public string WithdrawalKey;
public string BlockKey;
}
字段说明:
ErrorCode:错误代码Message:错误信息WithdrawalKey:账号处于注销等待状态时,用于恢复的密钥(仅注销等待中的账号提供)BlockKey:账号被封禁时提供的密钥(仅被封禁的账号提供)
iOS IAP 验证类
using System;
using System.Collections;
using UnityEngine.Networking;
public class IAPUnityIOS
{
static string path = "https://service-api.playnanoo.com/iap/v20221001/unity/ios";
[Serializable]
public class Req
{
public string receipt; // 영수증 정보
public string product_id; // 결제 상품 아이디
public string currency; // 화폐 코드 (KRW, JPY, USD, CNY...)
public string price; // 결제 금액
public string duplicate_allow; // 영수증 중복 검증 허용 여부
public IEnumerator Send(string receipt, string product_id, string currency, string price, bool duplicate_allow, Action<Res> onSuccess, Action<BaseResponse> onError)
{
if (!string.IsNullOrEmpty(receipt)) this.receipt = receipt;
if (!string.IsNullOrEmpty(product_id)) this.product_id = product_id;
if (!string.IsNullOrEmpty(currency)) this.currency = currency;
if (!string.IsNullOrEmpty(price)) this.price = price;
this.duplicate_allow = duplicate_allow ? "Y" : "N";
yield return HttpClient.Send<Req, Res>(
UnityWebRequest.kHttpVerbPUT,
path,
requireToken: true,
body: this,
onSuccess: onSuccess,
onError: onError
);
}
}
[Serializable]
public class Res : BaseResponse
{
public string UserID;
public string PackageName;
public string OrderID;
public string ProductID;
public string Currency;
public string Price;
}
}
使用示例
public void ValidateIOSIAP()
{
IAPUnityIOS.Req req = new IAPUnityIOS.Req();
// App Store 결제 정보
string receipt = "Base64EncodedReceiptData==";
string productId = "com.example.game.gold_100";
string currency = "USD";
string price = "0.99";
StartCoroutine(req.Send(
receipt: receipt,
product_id: productId,
currency: currency,
price: price,
duplicate_allow: false, // 중복 영수증 허용 안 함
onSuccess: res =>
{
Debug.Log($"IAP 검증 성공");
Debug.Log($"사용자 ID: {res.UserID}");
Debug.Log($"주문 ID: {res.OrderID}");
Debug.Log($"상품 ID: {res.ProductID}");
Debug.Log($"가격: {res.Price} {res.Currency}");
},
onError: (error) =>
{
Debug.LogError($"IAP 검증 실패: [{error.ErrorCode}] [{error.Message}]");
}
));
}
收据重复验证
将 duplicate_allow 设置为 false 时,无法使用同一收据进行重复验证。在测试环境中可以设置为 true 以允许重复验证。
App Store 收据
receipt 是 StoreKit 提供的 Base64 编码的收据数据。收据数据可以通过 appStoreReceiptURL 获取。
价格信息
price 必须以字符串形式传递实际支付金额。currency 使用 ISO 4217 货币代码。