页面上有paypal按钮。有 2 个带有 paypal 按钮的自定义字段。我在 ipn.php 页面上收到 IPN 响应。我从贝宝网站得到了这个代码。
当我使用沙盒进行测试时,付款是从买家账户中扣除并存入商家账户的。但是数据没有插入到我在下面的代码最后提到的数据库表中。我也尝试在名为“custom”的单个变量中发送两个变量值,但仍然没有运气。请检查我的代码,让我知道我做错了什么。请帮助我,因为我在过去 2 天都在挣扎。
$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]);
}
$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 (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'];
$custom_memname = $_POST['custom_memname']; // This is 1st custom variable
$custom_mempass = $_POST['custom_mempass']; // This is 2nd custom variable
$str_query_insert="insert into t_fmember(memberid,password) values('" .$custom_memname."','".$custom_mempass."')";
ExecuteQuery($str_query_insert);
}
我在我的 ipn.php 页面上添加了这段代码并使用了 IPN 模拟器,但还没有得到任何响应。
$post_data_string = serialize($_POST);
mail('mymail@yahoo.com', 'PayPal IPN', $post_data_string);
如果可能,请进一步提供帮助。谢谢