【发布时间】: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().'<hr/>', FILE_APPEND);它应该将所有内容记录到 html 文件中
标签: php curl paypal paypal-ipn