php - PayPal IPN 模拟器不工作?

标签 php paypal paypal-ipn

我正在尝试在事务完成后向我的数据库中插入一个新条目。所以我在我的服务器上创建了这个 IPN 监听器脚本:

    <?php

include 'MessageManager.php';

// STEP 1: read POST data
// Reading POSTed data directly from $_POST causes serialization issues with array data in the POST.
// Instead, read raw POST data from the input stream. 
$raw_post_data = file_get_contents('php://input');
$raw_post_array = explode('&', $raw_post_data);
$myPost = array();
foreach ($raw_post_array as $keyval) {
  $keyval = explode ('=', $keyval);
  if (count($keyval) == 2)
     $myPost[$keyval[0]] = urldecode($keyval[1]);
}
// read the IPN message sent from PayPal and prepend 'cmd=_notify-validate'
$req = 'cmd=_notify-validate';
if(function_exists('get_magic_quotes_gpc')) {
   $get_magic_quotes_exists = true;
} 
foreach ($myPost as $key => $value) {        
   if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) { 
        $value = urlencode(stripslashes($value)); 
   } else {
        $value = urlencode($value);
   }
   $req .= "&$key=$value";
}
$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, $req);
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'));
if( !($res = curl_exec($ch)) ) {
    error_log("Got " . curl_error($ch) . " when processing IPN data");
    curl_close($ch);
    exit;
}
curl_close($ch);

if (preg_match("!(VERIFIED)\s*\Z!",$res)){
    // assign posted variables to local variables
    $item_name = $_POST['item_name'];
    $payment_status = $_POST['payment_status'];
    $payment_amount = $_POST['mc_gross'];
    $quantity = $_POST['custom'];
    $receiver_email = $_POST['receiver_email'];

    if($payment_status === "Completed"){
        addMessage($item_name,(int) $quantity , $payment_amount);
    } else {
    }

} else {
}
?>

这是基于 PayPal 提供的脚本。我正在使用 IPN 模拟器来测试脚本。该脚本应该在销售完成后向我的数据库中插入一个新条目。插入代码本身运行良好,但是当我运行模拟器时,它在 paypal sute 上显示成功,但是我的数据库中没有新条目。

我做错了什么吗?

编辑:我收到此错误消息:

Failed 1SSL certificate problem

谢谢你。

最佳答案

尝试关闭 ssl 验证选项。我检查了我的 IPN 脚本,它就在那里。有 some caveats但它应该是安全的,因为您正在连接到 PayPal 并验证数据。

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

关于php - PayPal IPN 模拟器不工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29849995/

相关文章:

email - Paypal 沙盒新帐户电子邮件确认

php - 在不迁移的情况下向 Eloquent 模型添加一列 -PHP

php - RD_KAFKA_PARTITION_UA 在 librdkafka 中是如何工作的?

php - 在 nusoap wsdl 中定义 addcomplextype

c# - 与错误代码 : 10413 集成的购物车运费

php - Paypal IPN : how get the POSTs from this class?

php - 在 PHP 中使用 PayPal IPN 获取自定义字段

PHP 与 PayPal IPN 集成返回空 POST 数据

Paypal IPN 历史页面错误(重新发送消息不起作用)

php str_replace 是用什么字符串匹配算法写的?