gpt4 book ai didi

php - PayPal IPN 模拟器不工作?

转载 作者:太空宇宙 更新时间:2023-11-03 15:47:28 26 4
gpt4 key购买 nike

我正在尝试在事务完成后向我的数据库中插入一个新条目。所以我在我的服务器上创建了这个 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com