我正在使用PayPal IPN模拟器测试我的IPN通知程序。使用以下方法验证响应时:
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
我获得了无效
然而,当我使用这个(正确的)验证响应时:
$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
它不会返回VERIFIED OR 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);
}