Paypal IPN系统无法正常工作?

时间:2014-04-15 23:59:28

标签: php curl paypal paypal-ipn

这是我的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。我把它输出到一个文件,并且总是空的。我做了双倍和三重检查,我已经启用了卷曲。我不经常玩PHP,所以我可能做了一些我没见过的傻事。有谁知道它有什么问题?

1 个答案:

答案 0 :(得分:0)

事实证明我需要指定一个cacert文件。这导致ssl验证失败。