0

有人可以告诉我这段代码有什么问题吗?

我正在尝试使用 html 表单与 Paypal 进行支付集成。我已指定 notify_url,付款正常,但我无法进入此区块if (strcmp($res, "VERIFIED") == 0){}

// Response from Paypl
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
    $value = urlencode(stripslashes($value));
    $value = preg_replace('/(.*[^%^0^D])(%0A)(.*)/i', '${1}%0D%0A${3}', $value); // IPN fix
    $req .= "&$key=$value";
}

// assign posted variables to local variables
$data['item_name'] = $_POST['item_name'];

// post back to PayPal system to validate
$header = "POST /cgi-bin/webscr HTTP/1.0\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.sandbox.paypal.com', 443, $errno, $errstr, 30);

if (!$fp) {
    // HTTP ERROR
    echo 'HTTP ERROR';
} else {

    file_put_contents('test1.txt', 'test');
    fputs($fp, $header . $req);
    while (!feof($fp)) {
        $res = fgets($fp, 1024);
        if (strcmp($res, "VERIFIED") == 0) {
            echo 'SUCCESS';
        } else if (strcmp($res, "INVALID") == 0) {                
            echo 'INVALID';
        }
    }
    fclose($fp);
}
4

1 回答 1

1

使用 CuRl 方法而不是 fsock 来 POST 数据,这里是链接:https ://developer.paypal.com/webapps/developer/docs/classic/ipn/ht_ipn/或者我的建议是使用更有效和有用的 AngelaEye 库此处为 Paypal 集成链接:http : //www.angelleye.com/how-to-integrate-paypal-with-php-class-library/ 从此链接下载并浏览它。

于 2013-10-26T10:43:47.337 回答