我知道这个问题被问了很多,我已经看到了可能与这个问题相关的每一个问题,但似乎没有解决我的问题。基本上,当我在沙箱中运行代码时,它可以工作,但不能在现场运行。
<?php
class Paypal_IPN
{
/** @var string $_url The paypal url to go through cURL
$private $_url;
/**
* @param string $mode 'live' or 'sandbox'
*/
public function __construct($mode = 'live')
{
if ($mode == 'live')
$this->_url = 'https://www.paypal.com/cgi-bin/webscr';
else
$this->_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
}
public function run()
{
$postFields = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
if(function_exists('get_magic_quotes_gpc') and get_magic_quotes_gpc()){
$varvalue = urlencode(stripslashes($varvalue));
}
else {
$value = urlencode($value);
}
$postFields .= "&$key=$varvalue";
}
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => 'https://www.paypal.com/cgi-bin/webscr',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $postFields
));
$result = curl_exec($ch);
curl_close($ch);
$price = $_POST['mc_gross'];
if ($result == 'VERIFIED') {
try
{
$bdd = new PDO('mysql:host=HOST;dbname=DBNAME', 'LOGIN', 'PASS');
} catch(PDOexception $e)
{
echo "erreur";
}
$bdd->exec("UPDATE users SET price='$price' WHERE pseudo='CUSTOMER'");
} else {
// IPN invalid, log for manual investigation
echo "The response from IPN was: <b>" .$result ."</b>";
}
}
}
?>
所以是的,每次我进入运行这段代码的确认页面:
<?php
require 'ipn.php';
$paypal = new Paypal_IPN();
$paypal->run();
?>
IPN的响应是:INVALID我在paypal账户中输入了正确的IPN文件URL。我真的看不出我做错了什么。你们能帮我一下吗?
谢谢!
在public函数中,运行else
语句:
$value = urlencode($value);
应该是:
$varvalue = urlencode($value);