我有一些 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