我们的服务器需要提供一个URL来接收苹果的通知,要使用HTTPS。
苹果会对这个URL发送HTTP POST请求,body是JSON格式,包含了通知的内容。
我们服务器处理成功后,应向苹果返回HTTP 200。若出现问题,需要苹果重新发送通知,可返回HTTP 50x 或 40x。
environment字段表示通知对应的环境。若为Sandbox,表示测试环境,PROD表示生产环境。
unified_receipt 字段中包含了最近的交易信息。可通过其中的original_transaction_id找到对应原始订阅。
notification_type 表示触发此通知的事件类型。其值如下:
CANCEL:表示用户退款了,或者用户升级了订阅。(用户升级订阅后,会退款之前的订阅)
DID_CHANGE_RENEWAL_PREF:表示用户更改订阅计划,会在下次订阅生效。对当前订阅无影响。
DID_CHANGE_RENEWAL_STATUS:表示续订状态有改变。可检查auto_renew_status_change_date_ms和auto_renew_status字段。
DID_FAIL_TO_RENEW:表示由于账单问题,续订失败。可检查is_in_billing_retry_period
DID_RECOVER:表示成功续订。这个是针对过去续订失败的订阅。
INITIAL_BUY:表示第一次订阅。
INTERACTIVE_RENEWAL:表示用户手动续订成功。
RENEWAL:表示自动续订成功。(此字段苹果计划废弃,用DID_RECOVER代替。)
下面是常见的事件和触发的通知
首次购买:INITIAL_BUY
升级订阅:CANCEL, DID_CHANGE_RENEWAL_STATUS, INTERACTIVE_RENEWAL
降级订阅:INTERACTIVE_RENEWAL, DID_CHANGE_RENEWAL_PREF
订阅已过期,重新订阅:DID_CHANGE_RENEWAL_STATUS
订阅已过期,重新升级或降级订阅:INTERACTIVE_RENEWAL, DID_CHANGE_RENEWAL_STATUS
用户取消订阅:DID_CHANGE_RENEWAL_STATUS
用户退款:CANCEL, DID_CHANGE_RENEWAL_STATUS
由于账单问题,续订失败:DID_FAIL_TO_RENEW
账单问题解决,续订成功:DID_RECOVER
由于账单问题,订阅被彻底取消:DID_CHANGE_RENEWAL_STATUS
官方文档:https://developer.apple.com/documentation/storekit/in-app_purchase/enabling_server-to-server_notifications
例子
{
"latest_receipt": "***",
"latest_receipt_info": {
"original_purchase_date_pst": "2020-03-23 21:12:34 America/Los_Angeles",
"quantity": "1",
"subscription_group_identifier": "***",
"unique_vendor_identifier": "***",
"original_purchase_date_ms": "1585023154000",
"expires_date_formatted": "2020-04-24 04:12:33 Etc/GMT",
"is_in_intro_offer_period": "false",
"purchase_date_ms": "1585023153000",
"expires_date_formatted_pst": "2020-04-23 21:12:33 America/Los_Angeles",
"is_trial_period": "false",
"item_id": "***",
"unique_identifier": "***",
"original_transaction_id": "***",
"expires_date": "1587701553000",
"app_item_id": "***",
"transaction_id": "***",
"bvrs": "12",
"web_order_line_item_id": "***",
"version_external_identifier": "***",
"bid": "***",
"product_id": "***",
"purchase_date": "2020-03-24 04:12:33 Etc/GMT",
"purchase_date_pst": "2020-03-23 21:12:33 America/Los_Angeles",
"original_purchase_date": "2020-03-24 04:12:34 Etc/GMT"
},
"environment": "PROD",
"auto_renew_status": "true",
"unified_receipt": {
"latest_receipt": "***",
"pending_renewal_info": [
{
"original_transaction_id": "***",
"product_id": "***",
"auto_renew_status": "1",
"auto_renew_product_id": "***"
}
],
"environment": "Production",
"status": 0,
"latest_receipt_info": [
{
"expires_date_pst": "2020-04-23 21:12:33 America/Los_Angeles",
"purchase_date": "2020-03-24 04:12:33 Etc/GMT",
"purchase_date_ms": "1585023153000",
"original_purchase_date_ms": "1585023154000",
"transaction_id": "***",
"original_transaction_id": "110000712466308",
"quantity": "1",
"expires_date_ms": "1587701553000",
"original_purchase_date_pst": "2020-03-23 21:12:34 America/Los_Angeles",
"product_id": "***",
"subscription_group_identifier": "***",
"web_order_line_item_id": "***",
"expires_date": "2020-04-24 04:12:33 Etc/GMT",
"is_in_intro_offer_period": "false",
"original_purchase_date": "2020-03-24 04:12:34 Etc/GMT",
"purchase_date_pst": "2020-03-23 21:12:33 America/Los_Angeles",
"is_trial_period": "false"
}
]
},
"password": "***",
"auto_renew_product_id": "***",
"notification_type": "INITIAL_BUY"
}
网友评论