实时网站上的PayPal SSL错误

时间:2010-11-04 19:25:52

标签: php ssl paypal

我的PayPal代码在Sandbox上工作正常,但当我将其切换为live时,我遇到了错误。

function validate_send() {
    // https://www.paypal.com/us/cgi-bin/webscr?cmd=p/pdn/ipn-codesamples-pop-outside#php
    // http://stackoverflow.com/questions/3414479
    global $system;
    switch ($system->config['shop/mode']) {
    case 'live':
        $mode = 'www.paypal.com';
        break;
    case 'test':
        $mode = 'www.sandbox.paypal.com';
        break;
    default:
        trigger_error('Something\'s gone wrong!');
        break;
    }
    // Read the post from PayPal and add 'cmd'.
    $reply = array_merge(array('cmd' => '_notify-validate'), $_POST);
    $req = '';

    foreach ($reply as $k => $v) {
        if ($req) $req .= '&';
        $req .= $k . '=' . urlencode($v);
    }
    // Post back to PayPal to validate.
    $header  = 'POST /cgi-bin/webscr HTTP/1.0' . CR;
    $header .= 'Content-Type: application/x-www-form-urlencoded' . CR;
    $header .= 'Content-Length: ' . strlen($req) . CR . CR;
    $fp = fsockopen('ssl://' . $mode, 443, $errno, $errstr, 30);

    if (!$fp) {
        trigger_error('PayPal HTTP error');
    } else {
        fputs($fp, $header . $req);
        // Test the HTTP response code.
        $status = fgets($fp, 1024);
        $status = trim(substr($status, 9, 4));
        if ($status != 200) {
            return trigger_error('PayPal HTTP error: HTTP status code: ' . $status);
        }
        // Loop through response line by line, looking for response.
        while (!feof($fp)) {
            $res = fgets($fp, 1024);
            if (strcmp ($res, 'VERIFIED') == 0) {
                // Note: Checks mentioned in sample code are performed in the class Cart_External_PayPal_WebsitePaymentsStandard.
                return true;
            } elseif (strcmp ($res, 'INVALID') == 0) {
                return false;
            }
        }
    }
    fclose($fp);
}

第91行收到的错误为fgets(): SSL: fatal protocol error,这是while (!feof($fp))循环中的第一行。行$fp = fsockopen('ssl://' . $mode, 443, $errno, $errstr, 30);上的错误对我来说更有意义。

无论哪种方式,它在测试模式下都能正常工作,但在实时模式下会被破坏。怎么了?

0 个答案:

没有答案