php - Paypal IPN 系统无法正常工作?

标签 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。我已经将它输出到一个文件中,并且总是空的。我已经双重和三次检查我是否启用了 curl,我确实这样做了。我不经常玩 PHP,所以我可能做了一些我没见过的蠢事。有谁知道它有什么问题吗?

最佳答案

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

关于php - Paypal IPN 系统无法正常工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23096623/

相关文章:

php - 使用 PHP 和 Curl 将 Google AdWords API 用于关键字工具?

java - 如何将简单的 Curl 调用转换为 Java HttpURLConnection

php - 访问 PayPal 沙箱 Rest API 时响应 401

php - 在预算虚拟主机上运行的好 php 框架?

php - Openssl加密随 secret 钥&IV-存储在数据库中

php - 第一次访问后,使用 PHP cookie 自动填充以前用户输入的表单?

bash - 使用 xargs 进行并行curl API调用

php - 如何根据日期获取价格并将价格作为总价求和?

php - 使用 php 的自动付款通知

php - PayPal 沙箱不同于实时模式