这是我的 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,所以我可能做了一些我没见过的蠢事。有谁知道它有什么问题吗?
最佳答案
原来我需要指定一个 cacert 文件。它导致 ssl 验证失败。
关于php - Paypal IPN 系统无法正常工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23096623/