Here is the official guide to validate the receipt with Objective-C.
Receipt Validation Programming Guide
But here just use curl
to validate the in-app purchase receipt.
Validate API
There are two url to post the receipt to the apple api server. One is sandbox and another one is production.
https://sandbox.itunes.apple.com/verifyReceipt
https://buy.itunes.apple.com/verifyReceipt
Encode the receipt with base64
This api does not accept the raw receipt, but the base64 encoded value.
Here introduce two ways to encode the receipt.
Command Line
echo "receipt-string" | openssl enc -e -base64
Ruby Script
require 'base64'
str = "receipt-string"
p Base64.encode64(str)
POST encoded receipt
Here we use the curl
to post the encoded receipt to the apple api server.
curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST \
-d "Encoded-receipt" \
https://sandbox.itunes.apple.com/verifyReceipt
You will get a json result with status code, 0
is valid or error code here.