我正在使用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.0rn";
$header .= "Content-Type: application/x-www-form-urlencodedrn";
$header .= "Content-Length: " . strlen($req) . "rnrn";
$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