使用Typhoeus Gem从Ruby on Rails获得Apple Receipt验证21002

时间:2014-02-04 01:58:43

标签: ruby-on-rails json verification receipt typhoeus

我有一些rails代码可以获得Apple的应用程序内购买收据,并将其验证为沙箱或生产。这工作正常,但是最近我看到我的日志中有21002(收据数据属性中的数据格式错误)错误。我可以看到这些来自生产中的应用程序。

以下是我的验证收据的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

1 个答案:

答案 0 :(得分:2)

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

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

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