我正在尝试使用PayPal IPN系统。我已经设置了我的代码来使用他们的SandBox平台进行测试。我正在寻找一个原因,为什么我的代码的if (strcmp ($res, "VERIFIED") == 0) {
部分没有执行。不仅如此,此代码的任何部分都没有将任何输出写入“log.txt”。
我希望对我的代码进行审核,以便让我知道我哪里出错了。
<?php
require_once('includes/mysql.inc.php');
if($_POST) {
$req = 'cmd=' . urlencode('_notify-validate');
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
// post back to PayPal system to validate
$header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Host: sandbox.paypal.com\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('ssl://sandbox.paypal.com', 443, $errno, $errstr, 30);
if (!$fp) {
file_put_contents('log.txt', 'httperrrrr');
die();
} else {
file_put_contents('log.txt', 'die here');
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
$data = print_r($res, TRUE);
if (strcmp ($res, "VERIFIED") == 0) {
file_put_contents('log.txt', 'verified');
$username = $_POST['custom'];
require_once('classes/admin.class.php');
$activate = new Admin($db);
$activate->modifyUser($username, 'activate');
} else {
file_put_contents('log.txt', 'noverifyshit');
}
}
} else {
file_put_contents('log.txt', 'no post');
}
}
?>
答案 0 :(得分:0)
我修好了!我只是添加了“if($ _POST ['payment_status'] =”已完成“){”并且代码现在执行为true。
这是我更新的代码:
<?php
error_reporting(E_ALL);
ini_set('display_errors',1);
require_once('includes/mysql.inc.php');
if($_POST) {
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
// post back to PayPal system to validate
$header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Host: www.paypal.com\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
if (!$fp) {
file_put_contents('log.txt', 'httperrrrr');
die();
} else {
file_put_contents('log.txt', 'die here');
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
if ($_POST['payment_status'] = "Completed") {
file_put_contents('log.txt', 'verified');
$username = $_POST['custom'];
require_once('classes/admin.class.php');
$activate = new Admin($db);
$activate->modifyUser($username, 'activate');
}
} else {
file_put_contents('log.txt', $_POST['payment_status']);
}
}
}
}
?>