Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to verify Apple IAP receipt using php? [duplicate]

I am using php to write a server for iOS app.

I want to check receipt by accessing Apple's appstore server.

According to the apple's help document. I have to send a post request to apple's server.

http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/StoreKitGuide/VerifyingStoreReceipts/VerifyingStoreReceipts.html#//apple_ref/doc/uid/TP40008267-CH104-SW1

How can I do it by using php, many thanks!

Can any one give me an example?

like image 208
sxingfeng Avatar asked Jul 09 '12 15:07

sxingfeng


1 Answers

<?php

$applesharedsecret = "applesecretfromyourdevaccount";
$receiptbytes      = "......applereceipt.......";
$appleurl          = "https://buy.itunes.apple.com/verifyReceipt"; // for production
// use https://sandbox.itunes.apple.com/verifyReceipt for testing with sandbox receipt
$request = json_encode(array("receipt-data" => $receiptbytes,"password"=>$applesharedsecret));
$ch = curl_init($appleurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
$jsonresult = curl_exec($ch);
curl_close($ch);
var_dump($jsonresult); // see the details of the receipt.

?>
like image 59
suresh Avatar answered Nov 02 '22 23:11

suresh