如何使用PHP验证苹果IAP收据?

7

我建议您使用cURL,并使用https://dev59.com/M3M_5IYBdhLWcg3wn0pO来指导您。 - s1m0n
以下链接提供了PHP示例代码,用于验证苹果或谷歌支付的IAP。https://github.com/gcoolmaneric/VerifyStoreReceipt/blob/master/verifyPayment.php。 - Eric Wei
1个回答

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.

?>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接