贝宝 IPN 响应为空

PayPal IPN response empty

过去 5 个小时我一直在尝试调试这个问题and/or 在网上找到答案,但一切都是徒劳。我正在沙箱中进行测试,但实时服务器上存在同样的问题,这表明我的代码有问题而不是沙箱,但我无法弄清楚那是什么。我的代码基本上是直接从PayPal例子here.

复制过来的
// Step 2: POST IPN data back to PayPal to validate
$ch = curl_init();
$url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . '/cacert.pem');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));

if( !($res = curl_exec($ch)) ) {
    error_log("Got " . curl_error($ch) . " when processing IPN data");
    mail($notifyemail,'CURL error on IPN',"Got " . curl_error($ch) . " when processing IPN data");
    curl_close($ch);
    exit;
}
curl_close($ch);

(为简洁起见,我省略了这段代码上方的所有内容,但请放心,在此之前的所有代码都经过测试并验证可以正常工作。我已经用字符串和数组测试了 $req

在沙箱中测试时,它显示 IPN was sent and the handshake was verified(向我暗示端口 443 已打开)。但是,$res 始终为空。更奇怪的是,在我的调试过程中,我添加了一个步骤,我的代码在 curl_exec() 步骤之前和之后通过电子邮件将 curl_getinfo($ch) 的内容通过电子邮件发送给我,在这两种情况下,除了 url 之外的所有内容也是空的——就好像选项根本没有被添加到请求中一样。我对 curl 没有足够的经验,不知道这是否正常。

PayPal 对 IPN 的评价:

HTTP response code: 200
Delivery status: Sent
No. of retries: 0
IPN type: Transaction made

我尝试从 https://github.com/Quixotix/PHP-PayPal-IPN 交换库并改用它,它记录了 cURL error: [7](无法连接)这对我来说没有任何意义,因为再次握手验证。我把$listener->getTextReport()的内容发邮件给自己了,但是根本不包含任何错误信息。

尝试 use_ssluse_curl 的各种组合,我的错误日志如下所示:

[05-Oct-2016 16:40:13 America/Toronto] cURL error: [7] 
[05-Oct-2016 16:47:22 America/Toronto] PHP Warning:  fsockopen(): unable to connect to ssl://www.sandbox.paypal.com:443 (Operation not permitted) in /home/[stuff]/public_html/[stuff]/ipnlistener.php on line 144
[05-Oct-2016 16:47:22 America/Toronto] fsockopen error: [1] Operation not permitted
[05-Oct-2016 16:50:39 America/Toronto] cURL error: [7] 
[05-Oct-2016 16:51:55 America/Toronto] PHP Warning:  fsockopen(): unable to connect to www.sandbox.paypal.com:80 (Operation not permitted) in /home/[stuff]/public_html/[stuff]/ipnlistener.php on line 144
[05-Oct-2016 16:51:55 America/Toronto] fsockopen error: [1] Operation not permitted

一定有什么地方是我弄错了或忽略了,但我终究无法弄清楚那可能是什么。任何帮助将不胜感激。

嗯,问题似乎出在虚拟主机没有列入白名单 www.sandbox.paypal.com。因此,给遇到此问题的其他任何人一个教训:与您的网络托管服务商核实以确保一切都已准备就绪,让您可以做您需要做的事情。

Sidenote: 既然我已经有了使用经验,我推荐我在一天结束时开始使用的 IPN 库。在测试和实时环境之间以及 cURL 和套接字之间快速切换的能力非常有用和有益,它使我一天结束时的测试速度显着加快。