PayPal IPN 模拟器不工作?
PayPal IPN simuator not working?
我正在尝试在事务完成后向我的数据库中插入一个新条目。所以我在我的服务器上创建了这个 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);
我正在尝试在事务完成后向我的数据库中插入一个新条目。所以我在我的服务器上创建了这个 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);