[英]Paypal IPN works in sandbox but not live
我已从此处http://www.sanwebe.com/2012/07/paypal-instant-payment-notification-ipn/comment-page-1#comment-6871获取并改编了以下代码
<?php
include 'dbdata.php';
//Change these with your information
$paypalmode = 'sandbox'; //Sandbox for testing or empty ''
$paypalmode = '';
if($_POST)
{
if($paypalmode=='sandbox')
{
$paypalmode = '.sandbox';
}
$req = 'cmd=' . urlencode('_notify-validate');
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
$ch = curl_init();
//curl_setopt($ch, CURLOPT_URL, 'https://www'.$paypalmode.'.paypal.com/cgi-bin/webscr');
curl_setopt($ch, CURLOPT_URL, 'https://www.paypal.com/cgi-bin/webscr');
curl_setopt($ch, CURLOPT_HEADER, 0);
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_HTTPHEADER, array('Host: www'.$paypalmode.'.sandbox.paypal.com'));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: www.paypal.com'));
$res = curl_exec($ch);
curl_close($ch);
if (strcmp ($res, "VERIFIED") == 0)
{
$transactionID = $_POST['txn_id'];
$payerEmail = $_POST['payer_email'];
$paymentStatus = $_POST['payment_status'];
$firstName = $_POST['first_name'];
$surname = $_POST['last_name'];
$payerID = $_POST['payer_id'];
$addressName = $_POST['address_name'];
$addressCountry = $_POST['address_country'];
$addressCountryCode = $_POST['address_country_code'];
$addressZip = $_POST['address_zip'];
$addressState = $_POST['address_state'];
$addressCity = $_POST['address_city'];
$addressStreet = $_POST['address_street'];
$mcGross = $_POST['mc_gross'];
$mcShipping = $_POST['mc_shipping'];
$mcCurrency = $_POST['mc_currency'];
$paymentDate = $_POST['payment_date'];
$mdate= date('Y-m-d H:i:s',strtotime($paymentDate));
$otherStuff = json_encode($_POST);
$query5 = "INSERT INTO paypal (transationID,payerEmail,paymentStatus,firstName,surname,paymentDate,payerID,addressName,addressCountry,addressCountryCode,addressZip, addressState,addressCity,addressStreet,mcGross,mcShipping,mcCurrency,allData) VALUES ('".$transactionID."','".$payerEmail."','".$paymentStatus."','".$firstName."','".$surname."','".$mdate."','".$payerID."','".$addressName."','".$addressCountry."','".$addressCountryCode."','".$addressZip."','".$addressState."','".$addressCity."','".$addressStreet."','".$mcGross."','".$mcShipping."','".$mcCurrency."','".$otherStuff."')";
mysql_query($query5);
$mail_From = "xxx@googlemail.com";
$mail_To = "xxx@googlemail.com";
$mail_Subject = "VERIFIED IPN";
$mail_Body = $otherStuff;
//mail($mail_To, $mail_Subject, $mail_Body, $mail_From);
}
if (strcmp ($res, "INVALID") == 0)
{
$transaction_id = $_POST['txn_id'];
$payerid = $_POST['payer_id'];
$firstname = $_POST['first_name'];
$lastname = $_POST['last_name'];
$payeremail = $_POST['payer_email'];
$paymentdate = $_POST['payment_date'];
$paymentstatus = $_POST['payment_status'];
$mdate= date('Y-m-d h:i:s',strtotime($paymentdate));
$otherStuff = json_encode($_POST);
$query5 = "INSERT INTO paypal (transationID,payerEmail,paymentStatus) VALUES ('".$transaction_id."','".$payeremail."','".$paymentstatus."')";
mysql_query($query5);
}
}
?>
如果我使用沙盒模式和IPN模拟器,则会将数据正确插入表中。 现在,我已将客户的贝宝帐户的IPN设置设置为指向我的脚本并打开了IPN,但没有任何反应。
该网站正在使用快速结帐。 该网站位于美国。 php脚本托管在我们的服务器(英国)上。
贝宝显示已发送,如果我重新发送IPN,则它们会重新显示为已发送。 谁能看到这里出什么问题了?
另外,我没有从IPN获取我妻子的客户详细信息,但从模拟器获得了。
沃比先生
只需更换
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
与
foreach ($_POST as $key => $value){
$value = urlencode(stripslashes($value));
$value = preg_replace('/(.*[^%^0^D])(%0A)(.*)/i','${1}%0D%0A${3}',$value);// IPN fix
$req .= "&$key=$value";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.