验证Apple应用内购买(IAP)的支付凭证,该接口是轻量级的独立验证服务,不依赖于系统的订单体系。
Method | URI Path | 鉴权方式 |
---|---|---|
POST | /v1/apple/receipt/verify |
签名认证 |
参数名 | 类型 | 取值范围 | 是否必须 | 说明 |
---|---|---|---|---|
appkey | string | - | 是 | 在行云为应用分配的appkey |
timestamp | string | 10位数字 | 是 | 当前时间戳(秒级) |
sign | string | 32位小写字母和数字 | 是 | 签名,算法为:md5(appkey + timestamp + app_secret),app_secret为在行云为应用分配的appSecret |
参数名 | 类型 | 取值范围 | 是否必须 | 说明 |
---|---|---|---|---|
appkey | string | 最大64字符 | 是 | 应用标识 |
receipt_data | string | - | 是 | Apple收据数据(Base64编码) |
environment | string | Sandbox,Production | 是 | 验证环境 |
transaction_id | string | 最大128字符 | 是 | 要验证的具体交易ID |
transaction_id
参数用于精确指定要验证的交易,此参数为必填:
为什么必填:
参数来源:
SKPaymentTransaction.transactionIdentifier
获取系统行为:
latest_receipt_info
和 in_app
)查找指定的 transaction_id
curl --location --request POST 'https://api.zaihangyun.com/v1/apple/receipt/verify' \
--header 'User-Agent: Apifox/1.0.0 (https://apifox.com)' \
--header 'Accept: */*' \
--header 'Host: api.zaihangyun.com' \
--header 'Connection: keep-alive' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'appkey=D5fceA1sVtmaMY1x' \
--data-urlencode 'receipt_data=ewoJInNpZ25hdHVyZSIgPSAi...' \
--data-urlencode 'environment=Production' \
--data-urlencode 'transaction_id=2000000933865029' \
--data-urlencode 'timestamp=1745649979' \
--data-urlencode 'sign=e6d8c298f4f2b0eb1eaf60afc3653532'
curl --location --request POST 'https://api.zaihangyun.com/v1/apple/receipt/verify' \
--header 'User-Agent: Apifox/1.0.0 (https://apifox.com)' \
--header 'Content-Type: application/json' \
--header 'Accept: */*' \
--header 'Host: api.zaihangyun.com' \
--header 'Connection: keep-alive' \
--data-raw '{
"appkey": "D5fceA1sVtmaMY1x",
"receipt_data": "ewoJInNpZ25hdHVyZSIgPSAi...",
"environment": "Production",
"transaction_id": "2000000933865029",
"timestamp": "1745652994",
"sign": "79b4f3825a6e033da1b262bdff8147ce"
}'
{
"code": 200,
"msg": "success",
"data": {
"verification_id": 2017247833,
"status": "success",
"bundle_id": "com.kongmuhu.timestamp",
"environment": "Sandbox",
"transaction_id": "2000000933865029",
"original_transaction_id": "2000000933865029",
"product_id": "timestamp.kongmuhu.com.monthly_test",
"purchase_date": "2025-06-05 11:10:09",
"quantity": 1
}
}
{
"code": 400306,
"msg": "receipt verification failed",
"data": {
"verification_id": 3482881541,
"status": "failed",
"apple_status_code": 21002,
"error_message": "The data in the receipt-data property was malformed or missing."
}
}
{
"code": 400306,
"msg": "receipt already verified, duplicate verification not allowed"
}
{
"code": 400399,
"msg": "Transaction ID '2000000933865029' not found in receipt"
}
接口返回的是解析后的关键字段,完整的Apple原始票据数据已保存在系统中,可通过后台查看。
字段名 | 类型 | 说明 |
---|---|---|
verification_id | integer | 验证记录ID,用于查询完整票据数据 |
status | string | 验证状态:success |
bundle_id | string | 应用Bundle ID |
environment | string | 验证环境(Sandbox/Production) |
transaction_id | string | 交易ID(与请求参数中的transaction_id对应) |
original_transaction_id | string | 原始交易ID |
product_id | string | 苹果产品ID |
purchase_date | string | 购买时间 |
quantity | integer | 购买数量 |
expires_date | string | 过期时间(订阅产品,可选) |
is_trial_period | integer | 是否试用期:0=否,1=是(订阅产品,可选) |
cancellation_date | string | 取消时间(已取消的订阅,可选) |
字段名 | 类型 | 说明 |
---|---|---|
verification_id | integer | 验证记录ID |
status | string | 验证状态:failed |
apple_status_code | integer | Apple返回的状态码 |
error_message | string | 错误信息 |
系统保存的完整票据数据包含Apple的完整原始响应,主要包含以下结构:
receipt_type
: 收据类型adam_id
: App Store应用IDapp_item_id
: 应用项目IDbundle_id
: 应用Bundle IDapplication_version
: 应用版本download_id
: 下载IDversion_external_identifier
: 版本外部标识符receipt_creation_date
: 收据创建时间receipt_creation_date_ms
: 收据创建时间(毫秒)receipt_creation_date_pst
: 收据创建时间(PST)request_date
: 请求时间request_date_ms
: 请求时间(毫秒)request_date_pst
: 请求时间(PST)original_purchase_date
: 原始购买时间original_purchase_date_ms
: 原始购买时间(毫秒)original_purchase_date_pst
: 原始购买时间(PST)original_application_version
: 原始应用版本in_app
: 应用内购买交易数组包含所有交易信息,按时间降序排列,每个交易包含:
quantity
: 购买数量product_id
: 产品IDtransaction_id
: 交易IDoriginal_transaction_id
: 原始交易IDpurchase_date
: 购买时间purchase_date_ms
: 购买时间(毫秒)purchase_date_pst
: 购买时间(PST)original_purchase_date
: 原始购买时间original_purchase_date_ms
: 原始购买时间(毫秒)original_purchase_date_pst
: 原始购买时间(PST)expires_date
: 过期时间(订阅产品)expires_date_ms
: 过期时间(毫秒)expires_date_pst
: 过期时间(PST)web_order_line_item_id
: 网页订单行项目IDis_trial_period
: 是否试用期is_in_intro_offer_period
: 是否促销期subscription_group_identifier
: 订阅组标识符promotional_offer_id
: 促销优惠IDin_app_ownership_type
: 应用内购买所有权类型包含待续费信息:
auto_renew_product_id
: 自动续费产品IDoriginal_transaction_id
: 原始交易IDproduct_id
: 产品IDauto_renew_status
: 自动续费状态expiration_intent
: 过期原因grace_period_expires_date
: 宽限期过期时间grace_period_expires_date_ms
: 宽限期过期时间(毫秒)grace_period_expires_date_pst
: 宽限期过期时间(PST)is_in_billing_retry_period
: 是否在计费重试期offer_code_ref_name
: 优惠码引用名称price_consent_status
: 价格同意状态promotional_offer_id
: 促销优惠ID错误码 | 说明 |
---|---|
400101 |
appkey参数必填 |
400102 |
appkey参数长度不能超过64个字符 |
400103 |
receipt_data参数必填 |
400104 |
environment参数必填 |
400105 |
environment参数必须是Sandbox或Production |
400106 |
transaction_id参数必填 |
400107 |
transaction_id参数必须是字符串类型 |
400108 |
transaction_id参数长度不能超过128个字符 |
错误码 | 说明 |
---|---|
400300 |
订单接口配置未找到 |
400301 |
订单接口已关闭 |
400302 |
Apple验证功能已关闭,需要在在行云后台开启功能 |
400303 |
Apple验证配置缺失 |
400304 |
Bundle ID未配置 |
400305 |
共享密钥未配置 |
400306 |
收据已验证且不允许重复验证 |
400307 |
Bundle ID不匹配 |
400308 |
验证凭证失败,具体原因查看data字段(为apple返回错误信息) |
错误码 | 说明 |
---|---|
400399 |
收据验证失败(包括指定的transaction_id在收据中未找到) |