簡體   English   中英

PayPal IPN返回無效

[英]PayPal IPN returning INVALID

這是我用來解釋PayPal通知的代碼。 我不斷收到來自貝寶的“無效”信息。 對不起,這個問題本質上只是一個代碼片段,但是我已經研究了很長時間了,而且似乎沒有取得任何進展。

如果有人有任何想法,但需要查看一些調試信息,那么我設法通過php mail()函數來獲取它的方法-所以問一下就可以了。

<?php
    $debugmessage = "";

    require($_SERVER['DOCUMENT_ROOT'] . '/xxxx.php');
    mysql_connect("$server", "$user", "$password") or die(mysql_error());
    mysql_select_db("$database") or die(mysql_error());

    // read the post from PayPal system and add 'cmd'
    $req = 'cmd=_notify-validate';
    foreach ($_POST as $key => $value) {
        $value = urlencode(stripslashes($value));
        $req .= "&$key=$value";
    }

    // 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.paypal.com', 443, $errno, $errstr, 30);

    if (!$fp) {
        // HTTP ERROR
        echo "http error";
    } else {
        fputs ($fp, $header . $req);
        while (!feof($fp)) {
            $res = fgets ($fp, 1024);
            $debugmessage .= "|".$res;
            $debugmessage .= "|".strlen($req);
            if (strcmp ($res, "VERIFIED") == 0) {
                // PAYMENT VALIDATED & VERIFIED!
                $debugmessage .= "|"+"payment VALID";

                $email = $_POST['payer_email'];
                $password = mt_rand(100000, 999999);
                mysql_query("INSERT INTO users (email, password) VALUES('". mysql_escape_string($email) ."', '".md5($password)."' ) ") or die(mysql_error());
                $to      = $email;
                $subject = 'Download Area | Login Credentials';
                $message = '
                Thank you for your purchase!
                Your account information
                -------------------------
                Email: '.$email.'
                Password: '.$password.'
                -------------------------
                You can now login at xxxxxxxxxxxx';
                $headers = 'From:xxxxxxx@xxxxxxx.com' . "\r\n";
                mail($to, $subject, $message, $headers);
            }
            else if (strcmp ($res, "INVALID") == 0) {
                $debugmessage .= "|"."payment INvalid";
                // PAYMENT INVALID & INVESTIGATE MANUALY!
                $to      = 'xxxxxx@xxxxxxx.com';
                $subject = 'Download Area | Invalid Payment';
                $message = '
                Dear Administrator,
                A payment has been made but is flagged as INVALID.
                Please verify the payment manualy and contact the buyer.
                Buyer Email: '.$email.'
                ';
                $headers = 'From:xxxxxx@xxxxxxx.com' . "\r\n";
                mail($to, $subject, $message, $headers);

            }
        }
        fclose ($fp);
    }
    mail("xxxxxxx@gmail.com",$debugmessage,"");
?>

以防萬一有人理解可怕的混亂,腳本運行后, $debugmessage包含以下內容:

|HTTP/1.0 200 OK |840|X-Frame-Options: SAMEORIGIN |840|Strict-Transport-Security: max-age=14400 |840|Strict-Transport-Security: max-age=14400 |840|Content-Type: text/html; charset=UTF-8 |840|Date: Tue, 05 Mar 2013 04:42:09 GMT |840|Content-Length: 7 |840|Connection: close |840| |840|INVALID|840|payment INvalid

我已經讀過關於不使用fsockopen以及也使用“ CURL”的內容,但是我對這些東西不太有信心。

任何幫助將非常感激。

5小時后...我的解決方案是刪除代碼並使用本教程重做。

強烈推薦。

對於許多人來說,這似乎很明顯,但是我花了一些時間來弄清楚。 IPN模擬器請求已驗證,但歷史記錄中的IPN無效。 實際上,模擬用戶僅適用於沙箱,歷史記錄僅適用於普通網址。 您無法使用沙盒測試歷史IPN消息。

您可以嘗試使用PayPal Sandbox測試工具(即時付款通知(IPN)模擬器)來測試IPN。 在IPN文件中,您可以編寫包含POST數據的文件,並可以檢查出什么問題。

暫無
暫無

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

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