Paypal IPN 系统无法正常工作?

Posted

技术标签:

【中文标题】Paypal IPN 系统无法正常工作?【英文标题】:Paypal IPN System not working? 【发布时间】:2014-05-30 13:39:45 【问题描述】:

这是我的IPN代码(示例的修改版):

<?php
$ch = curl_init('https://www.sandbox.paypal.com/cgi-bin/webscr');
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, "cmd=_notify-validate&" . file_get_contents("php://input"));
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_HTTPHEADER, array('Connection: Close'));
$res = curl_exec($ch);
curl_close($ch);
if (strcmp ($res, "VERIFIED") == 0) 
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];
file_put_contents("ipn.txt", "cmd=_notify-validate&" . file_get_contents("php://input"));
else
file_put_contents("ipn.txt", "fail: " . $res);

?>

$res 变量似乎总是为空,尽管它应该是 INVALID 或 VERIFIED。我已将其输出到文件中,并且始终为空。我已经两次和三次检查我是否启用了 curl,我确实这样做了。我不经常玩 PHP,所以我可能做了一些我没见过的愚蠢的事情。有谁知道它有什么问题吗?

【问题讨论】:

这可能是一个非常愚蠢的问题,但是您的帐户中是否启用了 IPN? 试试:error_reporting(-1); 在第一行,var_dump($res); 在最后一行,你看到了什么? 我实际上并没有加载 PHP 文件,paypal 会。所以我看不到这样的东西,我必须将它们打印到文件中。是的,IPN 已启用。 @user2507230 将ob_start(); 放在最顶部,并在最后添加:file_put_contents('ipn_log.html', ob_get_contents().'&lt;hr/&gt;', FILE_APPEND); 它应该将所有内容记录到 html 文件中 【参考方案1】:

原来我需要指定一个 cacert 文件。它导致 ssl 验证失败。

【讨论】:

以上是关于Paypal IPN 系统无法正常工作?的主要内容,如果未能解决你的问题,请参考以下文章

PHP Paypal“官方”IPN 监听器无法正常工作

Paypal IPN 将无法正常工作

测试 IPN 不应该从我的 Paypal 沙盒帐户中取钱吗?

cURL Paypal IPN 脚本不工作

无法在 Codeigniter 中接收 PayPal IPN 响应

PayPal IPN 模拟器工作正常,但 IPN 不响应沙盒支付