簡體   English   中英

貝寶IPN PHP始終無效

[英]PayPal IPN php always INVALID

我已經嘗試編寫一個小型的PayPal IPN處理程序,但是在使用IPN模擬器https://developer.paypal.com/webapps/developer/applications/ipn_simulator時,我總是變得“無效”。 我不確定要發回的網址不正確。 我已經查看了一些有關該主題的要點,但它們似乎都有些曲折。 他們的文檔在這里https://developer.paypal.com/webapps/developer/docs/classic/ipn/integration-guide/IPNIntro/#protocol_and_arch ,我認為我已經遵循了協議的所有步驟。 任何幫助表示贊賞

<?php

    /**
     * Validates a PayPal IPN notification
     * @param  array $req The $_POST variable for the request
     * @return String     Returns the validity: 'VALID' or 'INVALID'
     */
    function verifyPayPalIPN($req) {

        // Base URL for the php validation
        $baseURL = 'https://www.paypal.com/cgi-bin/webscr?cmd=_notify-validate';

        // Loop through the POST parameters to 
        // create the validaton URL
        $postVars = '';
        foreach ($req as $key => $value) {
            $postVars .= $key . '=' . urlencode($value) . '&';
        }

        // Strip the last & off of the URL
        $postVars        = substr($postVars, 0, -1);

        // Send the request to PayPal to confirm 
        // whether the request to the script is 
        // from PayPal
        $requestValidity = system("curl --data '$postVars' $baseURL");

        return $requestValidity;
    }
    file_put_contents('/tmp/result.txt', verifyPayPalIPN($_POST));

?>

cmd=_notify-validate應該是postVars字符串的一部分

$baseURL = 'https://www.paypal.com/cgi-bin/webscr';

// Loop through the POST parameters to 
// create the validaton URL
$postVars = 'cmd=_notify-validate';
foreach ($req as $key => $value) {
    $postVars .= $key . '=' . urlencode($value) . '&';
}

我過去使用的代碼是這樣的:

$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
} else {

    fputs ($fp, $header . $req);
    while (!feof($fp)) {
        $res = fgets ($fp, 1024);
        if (strcmp ($res, "VERIFIED") == 0) {

        } else if (strcmp ($res, "INVALID") == 0) {

        }
    }
    fclose($fp);
}

注意端口號 也443

首先,檢查您的付費環境和驗證環境是否相同( sandbox或兩個production ),如果不相同,則說您的客戶在production環境中支付了訂單,然后您的PHP代碼嘗試請求sandbox環境端點驗證IPN請求,那么它將始終以INVALIDE結尾

暫無
暫無

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

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