簡體   English   中英

Paypal Sandbox IPN - 未得到驗證響應

[英]Paypal Sandbox IPN - Not getting VERIFIED response

我討厭問一個似乎以前被問過很多次的問題,但從閱讀許多帖子中我似乎無法弄清楚為什么我沒有從貝寶沙箱收到“已驗證”消息,我現在在這幾個現在幾個小時,並沒有進一步。

我將驗證調用的結果通過電子郵件發送給貝寶,下面是它所說的,但沒有“驗證”,我正在使用 IPN 模擬器進行測試https://developer.paypal.com/webapps/developer/applications/ipn_simulator

HTTP/1.0 302 找到位置: https ://www.sandbox.paypal.com 服務器:BigIP 連接:Keep-Alive Content-Length:0

<?php
    include("connect.php");

    // Send an empty HTTP 200 OK response to acknowledge receipt of the notification
    header('HTTP/1.1 200 OK');

    // Assign payment notification values to local variables
    $item_name        = $_POST['item_name'];
    $item_number      = $_POST['item_number'];
    $payment_status   = $_POST['payment_status'];
    $payment_amount   = $_POST['mc_gross'];
    $payment_currency = $_POST['mc_currency'];
    $payer_email      = $_POST['payer_email'];

    // Build the required acknowledgement message out of the notification just received
    $req = 'cmd=_notify-validate';               // Add 'cmd=_notify-validate' to beginning of the acknowledgement

    $msg = "";
    foreach ($_POST as $key => $value) {         // Loop through the notification NV pairs
        $value = urlencode(stripslashes($value));  // Encode these values
        $req  .= "&$key=$value";                   // Add the NV pairs to the acknowledgement
    }

    $req = "";

    // Set up the acknowledgement request headers
    $header  = "POST /cgi-bin/webscr HTTP/1.1\r\n";                    // HTTP POST request
    $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
    $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";

    // Open a socket for the acknowledgement request
    $fp = fsockopen ('www.sandbox.paypal.com', 80, $errno, $errstr, 30);

    // Send the HTTP POST request back to PayPal for validation
    fputs($fp, $header . $req);

    $result = "";
    while (!feof($fp))
    {                     // While not EOF
        $res=fgets($fp, 1024);               // Get the acknowledgement response
        $result .= $res;

        if (strcmp ($res, "VERIFIED") == 0){  // Response contains VERIFIED - process notification
            //db code here
        }
    }

    $to = 'test@email.com';
    $subject = 'Result';
    $m = $result;
    $headers = 'From: admin@email.com'."\r\n".
    'Reply-To: admin@email.com'."\r\n".
    'X-Mailer: PHP/'.phpversion();

    mail($to, $subject, $m, $headers);

    fclose($fp);  // Close the file
?>

您需要使用安全連接:

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

除了馬修的回應,我不得不添加一個附加行申報HTTP主機詳見這里

$header .= "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Host: www.sandbox.paypal.com\r\n";

此外,我無法讓 https:// 協議在我的服務器上運行,但將其切換為 ssl:// 對我有用, 這里有詳細的推理:

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

我在這個問題上花了幾個小時,上面沒有(以及網絡上的其他地方),但我的代碼在其他地方有錯誤。 這是代碼的混合,即使它們是在 Paypal 之后出現的,我也沒有更新 sql 連接。 基本上,一旦我修復了代碼,它就開始工作了。 代碼“好”,因為它可以在其他地方工作,但是有些特定部分沒有,sql 連接和表等我不太記得是什么。 但我會建議遇到此問題的人刪除所有其他代碼,直到他們可以檢查 Paypal IPN 是否正常工作。 就我而言,我糊塗了。 我連接到一個數據庫並發送 phpmailer 電子郵件,所以它是一個很長的腳本,在新環境中不起作用。 我想這使腳本失敗,即使我可以通過直接 URL 看到它顯然工作正常。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM