php苹果内购验证,苹果内购支付校验

PHP 苹果内购支付

正式验证地址: https://buy.itunes.apple.com/verifyReceipt

沙盒验证地址: https://sandbox.itunes.apple.com/verifyReceipt

/**

* 苹果内购Api查询接口

* Class AppleAipController

* @package Pay\Controller

*/

class AppleAipController extends Controller

{

/**

* @var string

*/

private $sandboxCurl = "https://sandbox.itunes.apple.com/verifyReceipt";

private $formalityCurl = "https://buy.itunes.apple.com/verifyReceipt";

/**

* @return array

*/

public function send($encodeStr,$sandboxStatus=0)

{

$ch = curl_init();

$data['receipt-data'] =$encodeStr;

$encodeStr = json_encode($data);

$url = $sandboxStatus?($this->formalityCurl):($this->sandboxCurl);

curl_setopt($ch, CURLOPT_URL,$url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

// post数据

curl_setopt($ch, CURLOPT_POST, 0);

// post的变量

curl_setopt($ch, CURLOPT_POSTFIELDS, $encodeStr);

curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);

$output = curl_exec($ch);

curl_close($ch);

$resut = (Array)json_decode($output,true);

return $resut;

}

}

相关资料

你可能感兴趣的:(php苹果内购验证)