1

我刚刚意识到我在 php 中的 paypal ipn 处理程序不再工作(我什么也没改变),我使用了 paypal 提供的示例 php 脚本。

我试图通过进行几次测试来隔离问题,此时我可以说问题不是“已验证”或“无效”的事情,而是来自以下几行:

[...]

fputs ($fp, $header . $req);
    while (!feof($fp))
    {
        $res = fgets ($fp, 1024);
        if (strcmp ($res, "VERIFIED") == 0)
        {
        // check the payment_status is Completed

[...]

任何人都知道贝宝是否改变了某些东西或为什么它不起作用?

谢谢'

ps:如果我把我的代码放在所有贝宝测试之前(在“if(!$fp)”行之前)它就可以正常工作

这是我的代码,我评论了“数据库进程”在哪里工作以及在哪里不工作。

<?php

// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';

foreach ($_POST as $key => $value)
{
    $value = urlencode(stripslashes($value));
    $req .= "&$key=$value";
}

// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);

// assign posted variables to local variables
$payment_status = $_POST['payment_status'];


// DATABASE PROCESS WORKS (BEFORE THE PAYPAL TESTS)



if (!$fp)
{
    // HTTP ERROR
}
else
   {

// DATABASE PROCESS WORKS

    fputs ($fp, $header . $req);
    while (!feof($fp))
    {
        $res = fgets ($fp, 1024);
        if (strcmp ($res, "VERIFIED") == 0)
        {
            // check the payment_status is Completed
            // check that txn_id has not been previously processed
            // check that receiver_email is your Primary PayPal email
            // check that payment_amount/payment_currency are correct
            // process payment


// DATABASE PROCESS NOT WORKING

        }
        else if (strcmp ($res, "INVALID") == 0)
        {
            // log for manual investigation

// DATABASE PROCESS NOT WORKING
        }
    }
fclose ($fp);
}

?>
4

2 回答 2

1

尝试在 x.xom https://www.x.com/instant-payment-notification-4上使用更新后的脚本

它使用 CURL 而不是 fsock

于 2012-10-01T19:29:32.827 回答
0

当服务器未正确配置套接字或未配置 openSSL 模块时发生此错误。

或者

您可以尝试使用以下代码示例,使用 file_get_contents 而不是 $fp 代码

<?php
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';

foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}

// for live mode
$url="https://www.paypal.com/cgi-bin/webscr";
// for developement mode
$url="https://www.sandbox.paypal.com/cgi-bin/webscr";

// instead of use of fopen you can use
$res=file_get_contents($url"?".$req);
// compare response
if (strcmp (trim($res), "VERIFIED") == 0) {
// check the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
// check that payment_amount/payment_currency are correct
// process payment
}
else if (strcmp (trim($res), "INVALID") == 0) {
// log for manual investigation
}

?>

如果 file_get_contents 不起作用,那么您可以使用 CURL 获取响应...

让我知道是否有任何问题?

谢谢

于 2012-09-29T09:36:28.063 回答