运行时 PHP 脚本问题

运行时 PHP 脚本问题

我有以下用于 iPhone 应用的应用内购买验证的 PHP 脚本。但是,该脚本(来自 chrismaddern)在本地主机(mac)上有效运行,但在我的实际服务器(Ubuntu 12)上无法运行或提供任何输出。以下是脚本:

<?php

function validateReceipt($receipt, $isSandbox = true)
{

if ($isSandbox) {
    $endpoint = 'https://sandbox.itunes.apple.com/verifyReceipt';
    print "Environment: Sandbox (use 'sandbox' URL argument to toggle)<br />";
}
else {
    $endpoint = 'https://buy.itunes.apple.com/verifyReceipt';
    print "Environment: Production (use 'sandbox' URL argument to toggle)<br />";
}

$postData = json_encode(
    array('receipt-data' => $receipt)
);


$ch = curl_init($endpoint);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);

$response = curl_exec($ch);
$errno    = curl_errno($ch);
$errmsg   = curl_error($ch);
curl_close($ch);

if ($errno != 0) {
    throw new Exception($errmsg, $errno);
}

$data = json_decode($response);

if (!is_object($data)) {
    throw new Exception('Invalid response data');
}

if (!isset($data->status) 
|| $data->status != 0) 
{
    print 'Status Code: '. $data->status . '<br/>';
    throw new Exception('Invalid receipt');
}

return array(
    'quantity'       =>  $data->receipt->quantity,
    'product_id'     =>  $data->receipt->product_id,
    'transaction_id' =>  $data->receipt->transaction_id,
    'purchase_date'  =>  $data->receipt->purchase_date,
    'app_item_id'    =>  $data->receipt->app_item_id,
    'bid'            =>  $data->receipt->bid,
    'bvrs'           =>  $data->receipt->bvrs
);
}


$receipt   = $_GET['receipt'];
$isSandbox = (bool) $_GET['sandbox'];

try {
 if(strpos($receipt,'{'))
{
$receipt = base64_encode($receipt);
}
$info = validateReceipt($receipt, $isSandbox);
echo 'Success';
//echo $info;
}
catch (Exception $ex) {
echo $ex->getMessage().'<br />';
}

为了测试目的,我手动以 base64 形式传递收据,以下是我在两种情况下得到的结果:

On LocalHost:环境:生产(使用“沙盒”URL 参数切换)成功

On Actual Server:环境:生产(使用“沙盒”URL 参数切换)

如您所见,实际服务器上没有输出。服务器操作系统是 Ubuntu 12.04,它可以顺利运行 PHP,因为我的网站和其他应用程序文件一直在运行。

所以有人能尽快提供解决方案吗?谢谢?>

答案1

您需要打开错误报告或检查错误日志以获取错误消息。也许 Ubuntu 服务器上未安装 curl?

相关内容