我的PHP IPN脚本不起作用-是什么导致它失败?

时间:2018-11-16 16:04:28

标签: php paypal paypal-sandbox paypal-ipn

您好StackOverflow社区! 我从事PayPal IPN脚本的研究已经有一段时间了,但没有取得太大的成功。该脚本应该返回VALID并将其放在stats.txt中,但是由于某种原因,这没有发生,而是根本无法正常工作。我使用了贝宝(PayPal)沙箱,并且foreach POST似乎工作正常。我尝试将带有所有GET值的原始URL放入浏览器,但是由于某种原因,贝宝只是给了我一个超时错误,甚至没有返回INVALID。这是我的代码:

// Get POST data and refine the GET value.
foreach ($_POST as $name => $value) {
    $postdata = $name.'='.$value.'&';
    $result .= substr('?'.$postdata, 0, -1);
}
// Verify that payment was really made.
    $verify = file_get_contents('https://ipnpb.sandbox.paypal.com/cgi-bin/webscr/'.$result.'');

if ($verify == "VERIFIED") {
    // Any code run here will only be run if payment is verified.
    echo 'Payment success!';
    $data = "Payment made successfully.";
    $fp = fopen('stats.txt', 'a');
    fwrite($fp, $data);
    }

    elseif ($verify == "INVALID") {
    echo 'Payment Declined.';
    $data = "The payment isn't valid.";
    $fp = fopen('stats.txt', 'a');
    fwrite($fp, $data);
}

else {
    echo 'An unexpected error occured.';
    $data = "A timeout error occured.";
    $fp = fopen('stats.txt', 'a');
    fwrite($fp, $data);
}

// Let PayPal know that the IPN was successful.
header("HTTP/1.1 200 OK");

付款后,在stats.txt中,我收到的文本是:发生超时错误。顺便说一句,最上面的部分是获取POST数据,然后将其格式化为GET网址(例如:?value1 = text1&value2 = text2)

感谢您的帮助!

0 个答案:

没有答案