【问题标题】:PayPal PDT SSL connection hangs up on my addon domainPayPal PDT SSL 连接挂断在我的插件域上
【发布时间】:2015-04-02 21:15:41
【问题描述】:

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

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

这就是我认为可能存在的问题(我希望有人能告诉我我是否走在正确的轨道上):我的 PDT 自动返回页面位于附加站点上,我认为当无法识别共享 SSL(用于我在共享服务器上的主域)时,PayPal 挂断。所以我要求我的网络主机专门为我的附加域安装 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);
}

【问题讨论】:

    标签: ssl paypal connection paypal-pdt


    【解决方案1】:

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

    【讨论】:

    • 感谢@tomwhipple。我废弃了我的代码版本并使用了 cURL 版本,效果很好。它完全使用不同的网址。我建议其他人也这样做。否则,这是一个潜在问题的雷区。
    猜你喜欢
    • 2016-06-02
    • 2014-07-16
    • 2017-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-20
    • 2015-03-26
    • 2018-03-25
    相关资源
    最近更新 更多