0

我正在尝试使用 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');
    }
}
?>
4

1 回答 1

0

我修好了它!我只是添加了 "if ($_POST['payment_status'] = "Completed") {" 并且代码现在执行为 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']);
            }
        }
    }
}
?>
于 2013-04-16T04:48:26.263 回答