1

在我的 PayPalautoReturn页面上,使用已知可工作的PHP脚本来适应支付数据传输,无论我做什么,我都会不断收到以下错误消息:"Warning: fgets(): SSL: Connection reset by peer...*(on the line where this is: '$line = fgets($fp, 1024);'* "

在我问我的问题之前,我只想说我已经尝试了这里以及我被建议阅读的任何其他论坛或文章中建议的所有内容,例如更改HTTP 1.0HTTP 1.1、使用$res=stream_get_contents($fp, 1024)而不是while loopwith$line = fgets($fp, 1024)等,等等。我的问题仍然存在。

这就是我认为可能存在的问题(我希望有人能告诉我我是否走在正确的轨道上):我的 PDT 自动退货页面位于附加网站上,我认为 PayPal 挂了当无法识别共享 SSL(对于我在共享服务器上的主域)时。所以我已经要求我的网络主机专门为我的附加域安装 SSL。

附加域 SSL 可能是我发出警告消息的原因吗?同样,该消息是:"Warning: fgets(): SSL: Connection reset by peer...*(on the line where this is: '$line = fgets($fp, 1024);'* "

这是我的代码:

 //look if the parameter 'tx' is set in the GET request and that it  does not have a null or empty value
if(isset($_GET['tx']) && ($_GET['tx'])!=null && ($_GET['tx'])!= "") {
    $tx = $_GET['tx'];

    verifyWithPayPal($tx);
}
else {
    exitCode();
}

function verifyWithPayPal($tx) {
    $req = 'cmd=_notify-synch';
    $tx_token = $tx;
    $auth_token = "MY SANDBOX AUTH_TOKEN HERE";
    $req .= "&tx=$tx_token&at=$auth_token";

    // 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";

    // url for paypal sandbox
    //$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno,   $errstr, 30);    

    // url for payal
    // $fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30);
    // If possible, securely post back to paypal using HTTPS
    // Your PHP server will need to be SSL enabled.

     $fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);

    if (!$fp) {
        exitCode();
    } else {
        fputs($fp, $header . $req);        
        // read the body data
        $res = '';
        $headerdone = false;

         while (!feof($fp)) {
            $line = fgets($fp, 1024);
        // $res=stream_get_contents($fp, 1024);
            if (strcmp($line, "\r\n") == 0) {
                // read the header
                $headerdone = true;
            }
            else if ($headerdone) {
                // header has been read. now read the contents
                $res .= $line;
            }
         }

        // parse the data
        $lines = explode("\n", $res);

        $response = array();

        if (strcmp ($lines[0], "SUCCESS") == 0) {

            for ($i=1; $i<count($lines);$i++){
                list($key,$val) = explode("=", $lines[$i]);
                $response[urldecode($key)] = urldecode($val);
            }

            $itemName = $response["item_name"];
            $amount = $response["payment_gross"];
            $myEmail = $response["receiver_email"];
            $userEmailPaypalId = $response["payer_email"];
            $paymentStatus = $response["payment_status"];
            $paypalTxId = $response["txn_id"];
            $currency = $response["mc_currency"];

            // check the payment_status is Completed
            if($paymentStatus!="Completed") {
                payment_complete();
                emailer($userEmailPayPalID);

            } else {
                payment_incomplete($paymentStatus);
            }

            /*
            // check that txn_id has not been previously processed
            checkIfTransactionHasAlreadyBeenProcessed($paypalTxId);
            // check that receiver_email is your Primary PayPal email
            checkThatPaymentIsReceivedAtYourEmailAddress($myEmail);
            // check that payment_amount/payment_currency are correct
            checkPaymentAmountAndCurrency($amount, $currency);
            // process the order
            processOrder();
            } else {
            exitCode();
            */
        }
    }
        fclose ($fp);
}
4

1 回答 1

1

我注意到您正在连接到www.sandbox.paypal.com. 我相信你想连接到api.sandbox.paypal.com.

于 2015-02-04T16:14:52.367 回答