PayPal IPN验证沙箱URL未验证或无效


PayPal IPN verify Sandbox URL not VERIFIED or INVALID

我正在使用PayPal IPN模拟器测试我的IPN通知器。当使用

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

我得到INVALID

但是当我使用这个(正确的)验证响应时:

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

它既不返回VERIFIED也不返回INVALID,只返回false。

完整代码在这里:

// 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