首页 文章

iOS应用程序内购买:消耗品的服务器端收据验证

提问于
浏览
0

我想为我正在开发的iOS应用程序实现应用程序内购买 consumable 产品 . 我想验证服务器端的收据,如documentation所示:

  • 应用程序启动事务询问Apple Store

  • Apple Store将回执发回给应用程序

  • 应用程序将收据发送到受信任的服务器

  • 可信服务器通过HTTP POST将收据(基本格式为64)发送到Apple Store

  • Apple Store通过验证回复HTTP POST

  • 如果验证响应正常,则可以启用购买

我担心以下情况:用户购买产品,Apple Store将收据发回给App(步骤1,2) . 然后,当应用尝试将收据发送到可信服务器时(步骤3),连接断开 . 在这种情况下,收据验证必须在第二时间重试,但是,我有以下问题:

a)在这种情况下,用户是否已经为产品付款?
b)自收到 consumable 产品compare only at the time of the purchase以来,如何管理验证重试?我应该在本地保存收据以便将来重新发送吗?我可以简单地将交易标记为“已完成"? From what I understand reading the documentation, in this case StoreKit should call the transaction queue observer again (passing again the receipt?) until the transaction is marked as "已完成”,是否正确?

先感谢您

1 回答

  • 1

    a) in this case, has the user already paid for the product?

    PaymentTransaction观察员将告诉您用户购买的状态是 .Purchased, .Purchasing, .Failed . 等等 .

    因此,我们可以从您的问题中假设用户的 state is .Purchased 并且您将收到付款 . 现在,由于他们有收据,并且希望通过真实购买,他们将等待您在服务器上进行验证并解锁购买,因为他们已收到包含有关其购买数据的收据 .

    b) Since receipts for consumable products compare only at the time of the purchase, how should the validation retry be managed? Should I save the receipt locally in order to retransmit it in the future? Can I simply does not mark the transaction as "finished"? From what I understand reading the documentation, in this case StoreKit should call the transaction queue observer again (passing again the receipt?) until the transaction is marked as "finished", is it correct?

    您无需在本地存储,并在收据中存储有关购买的信息 . 这将保留,直到您的paymentObserver完成交易或收据再次刷新/更新 . 您的应用程序将继续尝试验证您的服务器,直到收到有关收据的回复,通常是当用户再次启动应用程序时,如果我们认为它是有效的,您启用您的产品,然后在此完成SKPaymentQueue上的交易 .

    在它说的文档中

    “购买时,可将消费品的应用内购买收据添加到收据中 . 它会保留在收据中,直到您的应用完成该交易 . 在此之后,下次更新收据时将从收据中删除“

    https://developer.apple.com/library/archive/releasenotes/General/ValidateAppStoreReceipt/Chapters/ReceiptFields.html#//apple_ref/doc/uid/TP40010573-CH106-SW1

    另外:“例如,考虑用户在进入隧道之前在您的应用中购买东西的情况 . 您的应用无法提供已购买的内容,因为没有网络连接 . 下次启动应用程序时,StoreKit会再次调用您的事务队列观察器,并在此时提供所购买的内容 . 同样,如果您的应用程序未能将交易标记为已完成,则每次启动应用程序时,StoreKit都会调用观察者,直到交易正确完成为止 . “

    我希望这有帮助,我希望它能回答你的问题 .

相关问题