如何使用php验证Apple IAP收据?

时间:2012-07-09 15:15:31

标签: php ios in-app-purchase

我正在使用php为iOS应用程序编写服务器。

我想通过访问Apple的appstore服务器来查看收据。

根据苹果的帮助文件。我必须向苹果的服务器发送一个帖子请求。

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

我怎样才能使用php,非常感谢!

任何人都可以举个例子吗?

1 个答案:

答案 0 :(得分:7)

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

?>