我验证在服务器端的Mac App Store收到应用内购买(所谓的耗材).苹果服务器的响应通常如下:
{ "status"=>0,"environment"=>"Production","receipt" => { "receipt_type" => "Production","adam_id"=>410628904,"bundle_id" => "com.company.product","application_version"=>"1.0.0","download_id"=>002141541230420,"request_date"=>"2013-10-22 07:53:11 Etc/GMT","request_date_ms"=>"1382428391914","request_date_pst"=>"2013-10-22 00:53:11 America/Los_Angeles","original_purchase_date"=>"2011-08-22 06:05:47 Etc/GMT","original_purchase_date_ms"=>"1313993147000","original_purchase_date_pst"=>"2011-08-21 23:05:47 America/Los_Angeles","original_application_version"=>"1.0.0","in_app"=> [ { "quantity"=>"1","product_id"=>"com.company.product.mac_consumable","transaction_id"=>"9123912391231","original_transaction_id"=>"51881235936908","purchase_date"=>"2013-10-22 07:52:06 Etc/GMT","purchase_date_ms"=>"1382428326000","purchase_date_pst"=>"2013-10-22 00:52:06 America/Los_Angeles","original_purchase_date"=>"2013-10-22 07:52:06 Etc/GMT","original_purchase_date_ms"=>"1382428326000","original_purchase_date_pst"=>"2013-10-22 00:52:06 America/Los_Angeles","bundle_id"=>"com.company.product" } ] } }
但有时候,如果没有in_app哈希集,我们会收回信息:
{ "status"=>0,"adam_id"=>312621904,"in_app"=> [] } }
这是否意味着收据无效?应该填写in_app字段吗?或者这些收据是否也被认为是有效的,为什么in_app信息空?
解决方法
这是否意味着收据无效?
否,状态值为0,根据the docs表示收据有效.它只是不包含任何应用内购买“子收据”.
应该填写in_app字段吗?
不,收据可能不包含任何应用内购买.
显然,您的问题是,由于某种原因,您的应用程序发送到您的后端的收据不包含应用内购买的信息,即使您期望它.
当应用程序内购买交易进入“已购买”状态时,收据在客户端设备上应该是最新的 – 您应该确保在发生这种情况之前不要尝试将收据发送到服务器上.
考虑尝试的另一件事是SKReceiptRefreshRequest(仅在10.9之后可用) – 在某些边缘条件下,收据可能不是最新的,您需要等待更新才能将收据兑换请求发送到您的后端.