苹果内购支付校验

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实现apple API内购凭证的验证 实例代码
PHP 处理苹果内购二次验证 返回参数示例

IOS 内购开发:In-App Purchase

官方文档-App Store Receipts
官方文档-请求数据以及各式
官方文档-应用收据的状态

发表评论