2015-01-14 19:13
浏览 54


I need help with parsing the Apple receipt verification response (sandbox). So user makes the in-app purchase with the iPhone app, and sends me the receipt, which I validate using Apple Services () by PHP. The validation is okay, I get a response, so now I need to pull out a transaction ID so I can store it in the DB, but I don't know which receipt I should pull from the in_app key. There simply isn't a single receipt in there, but an array containing all of the previous receipts also. This response is gotten after a "Consumable" and "Non-Renewing Subscription" was made in the app.

I found a few articles covering this, but EACH were refering to the receipt directly, as it was a single property, which contains all the data, but not here.

Eg. https://github.com/chrismaddern/iOS-Receipt-Validator-PHP looks promising, but in the end he's opening the receipt in this way:

return $decoded_response->receipt;

Doesn't work for my response. I guess this is the old response or something.

This one also https://gist.github.com/jamesstout/5073237.

I'm dealing with this for the first time, any help would be appreciated, please tell me if you need additional information, I'll be glad to point it out.

Apple Response after receipt validation UPDATE:

Note about items in in_app array, those are the receipts, but not sorted in any way, so for example, original_purchase_date_pst is for the first 4 items:

[0] 2015-01-12 10:33:13 Etc/GMT
[1] 2015-01-12 11:35:53 Etc/GMT
[2] 2015-01-12 11:12:36 Etc/GMT
[3] 2015-01-12 11:15:57 Etc/GMT

I mean I could iterate through the whole array, but it seems a bit weird that there isn't an easier way to fetch the latest receipt. And can I be sure that there will be the latest receipt in the list ? I'll need to fetch the transaction ID from it so I must be sure!


图片转代码服务由CSDN问答提供 功能建议

我需要帮助解析Apple收据验证响应(沙盒)。 因此,用户使用iPhone应用程序进行应用程序内购买,并向我发送收据,我使用Apple的Apple Services()验证。 验证没问题,我得到了回复,所以现在我需要提取一个事务ID,这样我就可以将它存储在数据库中,但是我不知道应该从in_app密钥中提取哪个收据。 那里根本没有单个收据,但也有一个包含所有以前收据的数组。 在应用程序中进行“消耗品”和“非续订订阅”之后获得此响应。

我发现了一些涉及此内容的文章,但是每个人都直接参考了收据, 因为它是一个包含所有数据的单个属性,但不包含此处。

EG。 https://github.com/chrismaddern/iOS-Receipt-Validator-PHP看起来很有希望,但最后他以这种方式打开收据:

 返回$ decoding_response->收据; 

不适用于我的回复。 我想这是旧的回应或其他什么。

这个也是 https://gist.github.com/jamesstout/5073237

我是第一次处理此问题,如有任何帮助将不胜感激,请告诉我是否 你需要更多信息,我很乐意指出来。


注意in_app数组中的项目,这些是收据,但没有以任何方式排序,因此例如,original_purchase_date_pst是前4个 项目:

  [0] 2015-01-12 10:33:13 Etc / GMT 
 [1] 2015-01-12 11:35:53 Etc / GMT  
 [2] 2015-01-12 11:12:36 Etc / GMT 
 [3] 2015-01-12 11:15:57 Etc / GMT 

我的意思是我可以遍历整个数组,但似乎有点奇怪,没有一种更简单的方法来获取最新的收据。 我可以确定列表中会有最新的收据吗? 我需要从中获取交易ID,所以我必须确定!


  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douxing2652 2015-01-15 22:30

    So I want to answer this coz it might help somebody outthere, especially if the one is dealing with this for the first time.

    The thing that caused this structure of response wasn't on the PHP side, but on the iPhone code side. I'm not sure what happened there, but I asked the dev to send me his description of the problem so here it is (quoting):

    The problem was in receipt encoding, it was Apple documentation fail:

    enter image description here

    Apple say to use standard method of base64encoding - after that we receiveD that strange response with that in_app receipts array.

    I found on github a class which makes verifications which makes many tests:

    1) sends receipt to Apple 2) checks if transactionID is unique 3) checks if receipt or transaction objects are valid

    And I saw that they didn't use standard encoding method before sending, but they use custom category NSData+Base64. I added this category to project and encoded the receipt with method from this category. After that I started to receive responses with new structure - the one we need - with no receipts in array but single receipt with all needed data.

    解决 无用
    打赏 举报

相关推荐 更多相似问题