PayPal IPN和fsockopen不再受支持吗?

时间:2018-09-08 20:58:51

标签: php paypal paypal-ipn

多年来,我的PayPal IPN脚本一直有效。昨天它坏了,我们的Web服务器没有任何变化。当我收到IPN时,我的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.paypal.com', 443, $errno, $errstr, 120);
    if ($fp)
    {
        fputs ($fp, $header . $req);
        while (!feof($fp))
        {
          ...
        }
    }
}

PayPal的文档现在谈论:

将响应消息发送回PayPal:

https://ipnpb.sandbox.paypal.com/cgi-bin/webscr(用于沙盒IPN)

https://ipnpb.paypal.com/cgi-bin/webscr(用于实时IPN)

是否不再支持我的上述代码? PayPal打电话给我,但似乎没有验证。

1 个答案:

答案 0 :(得分:4)

这是HTTP / 1.1问题。

// post back to PayPal system to validate
$header = "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Host: www.paypal.com\r\n";
$header .= "Connection: close\r\n\r\n";

...

if (strcmp(trim($result), "VERIFIED") == 0)