0

我有一些 Rails 代码,它从 Apple 获得应用内购买收据,并针对沙盒或生产验证它。这工作得很好,但最近我在我的日志中看到了一些 21002(receipt-data 属性中的数据格式错误)错误。我可以看到这些来自生产中的应用程序。

下面是我验证收据的 RoR 代码,您是否看到任何会导致 21002 的内容?

非常感谢!

def verifyReceipt (receipt_data)

# Checking the magazine status to get the proper verification url 
if Publication.find_by_app_id(params[:app_id]).development_mode
    logger.info "Sandbox mode detected"
    url = "https://sandbox.itunes.apple.com/verifyReceipt"
else
    logger.info "Production mode detected"
    url = "https://buy.itunes.apple.com/verifyReceipt"
end

# Get the magazines shared secret
shared_secret = Publication.where("app_id = ?", params[:app_id]).first.itunes_shared_secret

if shared_secret.nil? or shared_secret.blank?
    # Invalid magazine
    logger.info "Shared secret does not exist or does not match iTunes shared secret!"
    result = false
else
    logger.info "Verifying receipt from Apple now!"
    # Verify receipt with apple based on magazine status, and save results
    data = { "receipt-data" => receipt_data, "password" => shared_secret }
    request = Typhoeus::Request.new(url, method: :post, body: data.to_json )
    request.run
    result = JSON.parse(request.response.body).with_indifferent_access
    logger.info "Result from verification: #{result[:status]}"
end
return result
end
4

1 回答 1

2

如果它在生产中,有时会出现 21002 错误是正常行为。

主要原因是有人在您的本地应用程序上使用 JB 设备或 IAP 破解程序并尝试进行虚假购买。假收据在 AppStore 验证中失败,返回 21002 错误。

您可以进行正式购买,以确保一切正常,以防万一。

于 2014-02-04T03:26:26.037 回答