7

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?

Machavity
  • 30,841
  • 27
  • 92
  • 100
sxingfeng
  • 971
  • 4
  • 15
  • 32
  • I'll recommend you to use cURL and use [http://stackoverflow.com/questions/1298998/verify-receipt-for-in-app-purchase][1] to guide you [1]: http://stackoverflow.com/questions/1298998/verify-receipt-for-in-app-purchase – s1m0n Jul 09 '12 at 16:54
  • The following link provides the example codes in PHP to validate IAP for Apple or Google Pay. https://github.com/gcoolmaneric/VerifyStoreReceipt/blob/master/verifyPayment.php. – Eric Wei Feb 12 '19 at 15:48

1 Answers1

16
<?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.

?>
suresh
  • 2,365
  • 1
  • 26
  • 36