在用苹果IAP进行内购时常见疑惑答疑,都是自己摸索的如有错误请评论告知
- 沙盒环境下,每天每个账号第一次购买会自动续期12次(包含第一次)
最后一次续期时的续费状态 auto_renew_status=1 仍然处于续费中
最后一次续费到期后后台会收到过期的通知 auto_renew_status = 0 - 只要成功购买了自动续费 auto_renew_status 就会变为 1,变成续费中
其状态在到达过期时间时才会收到通知改变为 0
首先我们都知道在storekit1中我们需要上传receipt(票据)让服务端去苹果后台验证是否是有效的票据,如果是给用户发放相应的权益,解析的票据见文章末尾。
疑问一: in_app:[] 和 latest_receipt_info:[] 中的数据数目为什么不一致,为什么有时候latest_receipt_info 比 in_app 中的数量多
答: 如果你的 in_app
中的数据比latest_receipt_info
中的数量少,那是因为你当前传给苹果的票据不是最新的票据,可以尝试用latest_receipt
重新请求一遍就可以看到两者数目数量是一致的了。经过我的测试我发现latest_receipt_info[].count > in_app [].count
疑问二:为什么 pending_renewal_info 中的 auto_renew_product_id 和 product_id 不一致
答:我们知道 pending_renewal_info 代表的是下个续费周期订阅的产品,特别是切换套餐时就会出现和我们当前已经订阅的套餐不一致的情况。在刚开始切换套餐的一段时间内比如我从 com.test.demo.month20
切换到 com.test.demo.month50
套餐,在一段时间内 pending_renewal_info
中的auto_renew_product_id 和 product_id 是不一致的,auto_renew_product_id
代表的是切换后的套餐(com.test.demo.month50)
。然而product_id
代表的是切换前的套餐(com.test.demo.month20)
。所以如果后台要跟踪用户下个周期扣哪个套餐的情况是一定要特别注意,去取auto_renew_product_id 的值才是正确的
疑问三:StoreKit 沙盒模式下订阅已订阅的订阅就会弹出以下弹框
此时重启App就会导致下面的回调函数被调用,并且重新创建的收据中所有以前的交易,同时transication_id还不存在于解析后的receipt中,导致上报给后台后后台找不到对应的订单
public func paymentQueue(_ queue: SKPaymentQueue,updatedTransactions transactions: [SKPaymentTransaction])
答:暂时无解,建议做成和苹果一样,订阅成功后把该项隐藏掉或者不可点击。哪位大佬知道其他办法可以评论一下,感谢
{
"environment": "Sandbox",
"receipt": {
"receipt_type": "ProductionSandbox",
"adam_id": 0,
"app_item_id": 0,
"bundle_id": "com.demo.test",
"application_version": "3999",
"download_id": 0,
"version_external_identifier": 0,
"receipt_creation_date": "2022-11-16 16:10:16 Etc/GMT",
"receipt_creation_date_ms": "1668615016000",
"receipt_creation_date_pst": "2022-11-16 08:10:16 America/Los_Angeles",
"request_date": "2022-11-16 16:10:55 Etc/GMT",
"request_date_ms": "1668615055425",
"request_date_pst": "2022-11-16 08:10:55 America/Los_Angeles",
"original_purchase_date": "2013-08-01 07:00:00 Etc/GMT",
"original_purchase_date_ms": "1375340400000",
"original_purchase_date_pst": "2013-08-01 00:00:00 America/Los_Angeles",
"original_application_version": "1.0",
"in_app": [
{
"quantity": "1",
"product_id": "com.test.demo.month20",
"transaction_id": "2000000204490048",
"original_transaction_id": "2000000204447356",
"purchase_date": "2022-11-16 15:33:58 Etc/GMT",
"purchase_date_ms": "1668612838000",
"purchase_date_pst": "2022-11-16 07:33:58 America/Los_Angeles",
"original_purchase_date": "2022-11-16 14:39:04 Etc/GMT",
"original_purchase_date_ms": "1668609544000",
"original_purchase_date_pst": "2022-11-16 06:39:04 America/Los_Angeles",
"expires_date": "2022-11-16 15:38:58 Etc/GMT",
"expires_date_ms": "1668613138000",
"expires_date_pst": "2022-11-16 07:38:58 America/Los_Angeles",
"web_order_line_item_id": "2000000015013502",
"is_trial_period": "false",
"is_in_intro_offer_period": "false",
"in_app_ownership_type": "PURCHASED"
},
],
"latest_receipt_info": [
{
"quantity": "1",
"product_id": "com.test.demo.month20",
"transaction_id": "2000000204490048",
"original_transaction_id": "2000000204447356",
"purchase_date": "2022-11-16 15:33:58 Etc/GMT",
"purchase_date_ms": "1668612838000",
"purchase_date_pst": "2022-11-16 07:33:58 America/Los_Angeles",
"original_purchase_date": "2022-11-16 14:39:04 Etc/GMT",
"original_purchase_date_ms": "1668609544000",
"original_purchase_date_pst": "2022-11-16 06:39:04 America/Los_Angeles",
"expires_date": "2022-11-16 15:38:58 Etc/GMT",
"expires_date_ms": "1668613138000",
"expires_date_pst": "2022-11-16 07:38:58 America/Los_Angeles",
"web_order_line_item_id": "2000000015013502",
"is_trial_period": "false",
"is_in_intro_offer_period": "false",
"in_app_ownership_type": "PURCHASED"
},
{
"quantity": "1",
"product_id": "com.test.demo.month20",
"transaction_id": "2000000204490048",
"original_transaction_id": "2000000204447356",
"purchase_date": "2022-11-16 15:33:58 Etc/GMT",
"purchase_date_ms": "1668612838000",
"purchase_date_pst": "2022-11-16 07:33:58 America/Los_Angeles",
"original_purchase_date": "2022-11-16 14:39:04 Etc/GMT",
"original_purchase_date_ms": "1668609544000",
"original_purchase_date_pst": "2022-11-16 06:39:04 America/Los_Angeles",
"expires_date": "2022-11-16 15:38:58 Etc/GMT",
"expires_date_ms": "1668613138000",
"expires_date_pst": "2022-11-16 07:38:58 America/Los_Angeles",
"web_order_line_item_id": "2000000015013502",
"is_trial_period": "false",
"is_in_intro_offer_period": "false",
"in_app_ownership_type": "PURCHASED"
}
],
},
"latest_receipt": "****",
"pending_renewal_info": [
{
"expiration_intent": "1",
"auto_renew_product_id": "com.test.demo.month50",
"is_in_billing_retry_period": "0",
"product_id": "com.test.demo.month20",
"original_transaction_id": "2000000204447356",
"auto_renew_status": "0"
}
],
"status": 0
}