gpt4 book ai didi

ios - 检查自动续订订阅是否过期

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:20:21 24 4
gpt4 key购买 nike

我已经设置了一个沙盒用户,并在我的 iPhone 设备上成功地为他们订阅了一个月的自动续订订阅。如何检测用户的订阅是否已结束?

我有以下代码:

[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];

它最终会调用这个方法和逻辑:

- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
{
for (SKPaymentTransaction *transaction in queue.transactions) {
if (transaction.transactionState == SKPaymentTransactionStateRestored) {
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
[self setSubscriptionActive]; // <-- Probably not the right way to restore subscriptions?
return; // Return because we have successfully set the subscribed state of the app.
}
}
[self purchase:self.validProduct]; // No valid transactions, so ask them to purchase.
}

我的问题是,根据我目前的逻辑,现在已经两个小时了,这个测试用户总是到达代码行,[self setSubscriptionActive];,因此我已经支付了唯一的款项在他的测试账户下总是返回SKPaymentTransactionStateRestored。我希望它现在到期 according to the documentation from Table 3-1 (Subscription durations for testing) ...所以现在我想知道,我是不是做错了什么,和/或有人知道验证这个为期一个月/及时的订阅是否已过期的正确方法是什么吗?

我什至尝试在 Apple 的沙箱服务器上按照他们的收据验证文章对收据进行 JSON 查询。仔细查看这些数据,亲眼看看这一切有多糟糕:

"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";
"receipt_creation_date" = "2016-08-18 01:05:09 Etc/GMT";
"receipt_creation_date_ms" = 1471482309000;
"receipt_creation_date_pst" = "2016-08-17 18:05:09 America/Los_Angeles";
"receipt_type" = ProductionSandbox;
"request_date" = "2016-08-18 01:05:09 Etc/GMT";
"request_date_ms" = 1471482309971;
"request_date_pst" = "2016-08-17 18:05:09 America/Los_Angeles";

我看到了两个问题:

  1. 这是第一次购买,但它显示 original_purchase_date2013-08-01 07:00:00 Etc/GMT。我今天买了它。这次离 8 月 17 日还很远。这是非常不正确的。

  2. receipt_creation_date2016-08-18 01:05:09 Etc/GMTrequest_date2016-08-18 01:05:09 Etc/GMT...我必须在创建收据的那一瞬间发出网络请求。我假设 request_date(就像这个垃圾 API 中的大部分一样)没有记录它的有效互联网时间,所以你可以用它来比较(而不是本地时间)它和receipt_creation_date。上帝啊,这真是一场噩梦……为什么有人会允许任何人制作这样一个如此复杂、荒谬的后端系统?这太可怕了。真可惜,因为 Apple 的其他 API 总体上都很好。

最佳答案

不要手动计算日期。根据Apple's Validate App Store Receipt ,您应该使用 expires_date

This key is only present for auto-renewable subscription receipts. Use this value to identify the date when the subscription will renew or expire, to determine if a customer should have access to content or service. After validating the latest receipt, if the subscription expiration date for the latest renewal transaction is a past date, it is safe to assume that the subscription has expired.

关于ios - 检查自动续订订阅是否过期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39007161/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com