我有以下PHP PayPal IPN,它在几天前一直运行良好。
然而,自从昨晚以来,它突然停止工作,并且我在paypal沙盒ipn模拟器中测试多少次并不重要,它只是没有在MYSQL数据库中插入任何内容!
我没有更改我的php文件中的任何内容,所以我不明白为什么会出现这个问题。
这是我的全部代码:
<?php
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(-1);
$murl = "http://".$_SERVER['HTTP_HOST'];
// Check to see there are posted variables coming into the script
if ($_SERVER['REQUEST_METHOD'] != "POST") die ("No Post Variables");
// Initialize the $req variable and add CMD key value pair
$req = 'cmd=_notify-validate';
// Read the post from PayPal
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
// Now Post all of that back to PayPal's server using curl, and validate everything with PayPal
// We will use CURL instead of PHP for this for a more universally operable script (fsockopen has issues on some environments)
//$url = $paypal_url;
$url = "https://www.sandbox.paypal.com/cgi-bin/webscr";
$curl_result=$curl_err='';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($req)));
curl_setopt($ch, CURLOPT_HEADER , 0);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$curl_result = @curl_exec($ch);
$curl_err = curl_error($ch);
curl_close($ch);
$req = str_replace("&", "\n", $req); // Make it a nice list in case we want to email it to ourselves for reporting
// Check that the result verifies
if (strpos($curl_result, "VERIFIED") !== false) {
$req .= "\n\nPaypal Verified OK";
} else {
$req .= "\n\nData NOT verified from Paypal!";
mail("myemail@yahoo.co.uk", "IPN interaction not verified", "$req", "From: myemail@yahoo.co.uk" );
exit();
}
/* CHECK THESE 4 THINGS BEFORE PROCESSING THE TRANSACTION, HANDLE THEM AS YOU WISH
1. Make sure that business email returned is your business email
2. Make sure that the transactions payment status is completed
3. Make sure there are no duplicate txn_id
4. Make sure the payment amount matches what you charge for items. (Defeat Price-Jacking) */
// Check Number 1 ------------------------------------------------------------------------------------------------------------
include "config/connect.php";
$storePayment = "".$paypal_email."";
$receiver_email = $_POST['receiver_email'];
if ($receiver_email != $storePayment) {
$message = "Investigate why and how receiver email is wrong. Email = " . $_POST['receiver_email'] . "\n\n\n$req";
mail("myemail@yahoo.co.uk", "Receiver Email is incorrect", $message, "From: myemail@yahoo.co.uk" );
exit(); // exit script
}
// Check number 2 ------------------------------------------------------------------------------------------------------------
if ($_POST['payment_status'] != "Completed") {
// Handle how you think you should if a payment is not complete yet, a few scenarios can cause a transaction to be incomplete
}
// Connect to database ------------------------------------------------------------------------------------------------------
require_once 'config/connect.php';
// Check number 3 ------------------------------------------------------------------------------------------------------------
$this_txn = $_POST['txn_id'];
$stmt = $db_conx->prepare("SELECT id
FROM yt_transactions
WHERE txn_id = ?");
$stmt->bind_param('s', $this_txn);
$stmt->execute();
$stmt->bind_result($this_txn);
$stmt->store_result();
if($stmt->num_rows == 0) //To check if the row exists
{
while($stmt->fetch()) //fetching the contents of the row
{
$message = "Duplicate transaction ID occured so we killed the IPN script. \n\n\n$req";
mail("noreply@mrshopp.com", "Duplicate txn_id in the IPN system", $message, "From: noreply@mrshopp.com" );
exit(); // exit script
}
}
$stmt->close();
include "config/connect.php";
// Check number 4 ------------------------------------------------------------------------------------------------------------
$product_id_string = mysqli_real_escape_string($db_conx, $_POST['custom']);
//$product_id_string = rtrim($product_id_string, ","); // remove last comma
// Explode the string, make it an array, then query all the prices out, add them up, and make sure they match the payment_gross amount
//$id_str_array = explode(",", $product_id_string); // Uses Comma(,) as delimiter(break point)
// END ALL SECURITY CHECKS NOW IN THE DATABASE IT GOES ------------------------------------
////////////////////////////////////////////////////
// Homework - Examples of assigning local variables from the POST variables
$item_name = mysqli_real_escape_string($db_conx, $_POST['item_name']);
$first_name = mysqli_real_escape_string($db_conx, $_POST['first_name']);
$last_name = mysqli_real_escape_string($db_conx, $_POST['last_name']);
$payment_date = mysqli_real_escape_string($db_conx, $_POST['payment_date']);
$mc_gross = mysqli_real_escape_string($db_conx, $_POST['mc_gross']);
$payment_currency = mysqli_real_escape_string($db_conx, $_POST['payment_currency']);
$payment_type = mysqli_real_escape_string($db_conx, $_POST['payment_type']);
$payment_status = mysqli_real_escape_string($db_conx, $_POST['payment_status']);
$txn_type = mysqli_real_escape_string($db_conx, $_POST['txn_type']);
$payment_type = mysqli_real_escape_string($db_conx, $_POST['payment_type']);
$payer_status = mysqli_real_escape_string($db_conx, $_POST['payer_status']);
$address_street = mysqli_real_escape_string($db_conx, $_POST['address_street']);
$address_city = mysqli_real_escape_string($db_conx, $_POST['address_city']);
$address_state = mysqli_real_escape_string($db_conx, $_POST['address_state']);
$address_zip = mysqli_real_escape_string($db_conx, $_POST['address_zip']);
$address_country = mysqli_real_escape_string($db_conx, $_POST['address_country']);
$address_status = mysqli_real_escape_string($db_conx, $_POST['address_status']);
$notify_version = mysqli_real_escape_string($db_conx, $_POST['notify_version']);
$verify_sign = mysqli_real_escape_string($db_conx, $_POST['verify_sign']);
$payer_id = mysqli_real_escape_string($db_conx, $_POST['payer_id']);
$mc_currency = mysqli_real_escape_string($db_conx, $_POST['mc_currency']);
$mc_fee = mysqli_real_escape_string($db_conx, $_POST['mc_fee']);
$txn_id = mysqli_real_escape_string($db_conx, $_POST['txn_id']);
$payer_email = mysqli_real_escape_string($db_conx, $_POST['payer_email']);
$custom = mysqli_real_escape_string($db_conx, $_POST['custom']);
// Place the transaction into the database
$stmt = mysqli_prepare(
$db_conx,
"INSERT INTO yt_transactions (product_id_array, payer_email, first_name, last_name, item_name, payment_date, mc_gross, payment_currency, txn_id, receiver_email, payment_type, payment_status, txn_type, payer_status, address_street, address_city, address_state, address_zip, address_country, address_status, notify_version, verify_sign, payer_id, mc_currency, mc_fee) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
);
//after validation, of course
mysqli_stmt_bind_param($stmt, "sssssssssssssssssssssssss", $custom, $payer_email, $first_name, $last_name, $item_name, $payment_date, $mc_gross, $payment_currency, $txn_id, $receiver_email, $payment_type, $payment_status, $txn_type, $payer_status, $address_street, $address_city, $address_state, $address_zip, $address_country, $address_status, $notify_version, $verify_sign, $payer_id, $mc_currency, $mc_fee);
mysqli_stmt_execute($stmt);
if (mysqli_affected_rows($db_conx))
{
mysqli_stmt_close($stmt);//<-- CLEAN UP AFTER YOURSELF!
//update was successful
$id = mysqli_insert_id($db_conx);
}
//mysqli_close($db_conx);
// Mail yourself the details
mail("".$paypal_email."", "You have a payment!", $req, "From: ".$paypal_email."");
?>
任何帮助将不胜感激。
提前致谢。