我有一个PayPal IPN脚本,该脚本已经正常运行了几年。 PayPal历史记录表明它们仍在正确发送,并且显示的HTTP代码为200。数据不再写入数据库。代码在下面。我没有更改脚本中的任何内容。我已经读过,贝宝(Paypal)不再接受HTTP 1.0,但是在这里似乎不适用。有人没有任何建议吗?
<?php
//Change these with your information
$paypalmode = ''; //Sandbox for testing or empty ''
$dbusername = '************'; //db username
$dbpassword = '************'; //db password
$dbhost = '************'; //db host
$dbname = '***************'; //db name
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.'.ipnpb.paypal.com/cgi-bin/webscr'); // added .ipnpb
curl_setopt($ch, CURLOPT_HEADER, 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_HTTPHEADER, array('Host:www'.$paypalmode.'.ipnpb.sandbox.paypal.com'));
$res = curl_exec($ch);
curl_close($ch);
if (strcmp ($res, "VERIFIED") == 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));
//$sender_email= $_POST['sender_email'];
$custom= $_POST['custom'];
$otherstuff = json_encode($_POST);
$conn = mysql_connect($dbhost,$dbusername,$dbpassword);
if (!$conn)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db($dbname, $conn);
// insert in our IPN record table
$query = "INSERT INTO ibn_table
(itransaction_id,ipayerid,iname,iemail,itransaction_date, ipaymentstatus,ieverything_else, custom)
VALUES
('$transaction_id','$payerid','$firstname $lastname','$payeremail','$mdate', '$paymentstatus','$otherstuff','$custom')";
if(!mysql_query($query))
{
//mysql error..!
}
// mysql_close($conn);
}
//mysql_select_db($dbname, $conn);
// Update sender email
//$query2 = "UPDATE `ibn_table` SET `sender_email`=`iemail` WHERE `sender_email` = ''";
// if(!mysql_query($query2))
// {
//mysql error..!
// }
// mysql_close($conn);
}