简体   繁体   中英

PayPal IPN verify Sandbox URL not VERIFIED or INVALID

I am testing my IPN notifier using the PayPal IPN simulator. When verifying the response using:

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

I get INVALID

however when I verify the response using this one (the correct one):

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

it does not return either VERIFIED OR INVALID, just false.

Full code here:

// read the data send by PayPal
$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.sandbox.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) {
            //verified
        }
        else if (strcmp ($res, "INVALID") == 0) {
            //invalid
        }
    }
    fclose ($fp);
}

最终使用了似乎可以正常工作的cURL https://gist.github.com/CodeAngry/5957044

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM