gpt4 book ai didi

ios - Apple 应用内购买收据 - 在服务器端验证

转载 作者:可可西里 更新时间:2023-11-01 03:35:02 24 4
gpt4 key购买 nike

我在服务器端验证苹果收据时遇到问题。我试图在互联网上找到解决方案,但没有成功。

所以,描述:首先,应用程序是为 iOS7 制作的。其次,我有一些项目( type = Non-Renewing Subscription )。所以用户可以购买一件或多件商品,然后他应该手动更新它们(再次购买)。

应用程序向服务器端发送收据,我向 Apple 发出请求并获得包含很多 in_app 收据的结果。像这样的东西:

"in_app":[
{
"quantity":"1", "product_id":"...", "transaction_id":"...",
"original_transaction_id":"...", "purchase_date":"...",
"purchase_date_ms":"...", "purchase_date_pst":"...",
"original_purchase_date":"...",
"original_purchase_date_ms":"...", "original_purchase_date_pst":"...",
"is_trial_period":"..."},
{
"quantity":"1", "product_id":"...",
"transaction_id":"...","original_transaction_id":"...",
"purchase_date":"...", "purchase_date_ms":"...",
"purchase_date_pst":"...", "original_purchase_date":"...",
"original_purchase_date_ms":"...", "original_purchase_date_pst":"...",
"is_trial_period":"..."}
]

因此,“in_app”中的每个“收据”都有 transaction_id。但是我如何识别当前购买的 transactionId 呢?我也想验证它并确保它是唯一的。

我担心的是:如果有人得到一张有效收据,他将能够破解我们的服务器端 API,并使用同一张有效收据进行无限次的应用内购买。

我是否应该以某种方式解密并检查“原始”收据的 transaction_id,即我发送给 Apple 进行验证的收据?

如有任何帮助/建议,我们将不胜感激。提前谢谢你。

问候,马克西姆

最佳答案

@道格·史密斯

https://developer.apple.com/library/ios/releasenotes/General/ValidateAppStoreReceipt/Chapters/ReceiptFields.html

如果您浏览此页面上的不同字段,您会发现

Original Transaction Identifier:: For a transaction that restores a previous transaction, the transaction identifier of the original transaction. Otherwise, identical to the transaction identifier. This value corresponds to the original transaction’s transactionIdentifier property. All receipts in a chain of renewals for an auto-renewable subscription have the same value for this field.

因此对于您的非自动续订订阅,您必须在服务器端跟踪两件事:

  1. 您正在使用 iTunes 服务器验证的收据的原始交易标识符,将其与您数据库中的用户 ID 相关联。
  2. 您从客户端收到的请求是购买请求还是恢复购买请求。

一旦你有了这两个东西,你就可以像下面这样在这两个参数上写你的逻辑了:

::如果请求的类型为“购买”,并且您已经拥有与其他用户 ID 相关联的该收据的原始交易标识符,您可以阻止该购买。

::如果请求的类型为“恢复购买”,并且请求来自与数据库中原始交易标识符相关联的同一用户 ID,则允许他以其他方式阻止他的恢复。

此外,您还可以根据需要根据这些东西推导出自己的逻辑。

如果您还有任何疑问,请告诉我。

关于ios - Apple 应用内购买收据 - 在服务器端验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27940995/

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