PayPal即时付款通知PHP

时间:2013-08-12 12:16:17

标签: php paypal-ipn

问题是Paypal没有对此请求作出回应。以下是我使用的示例代码

我使用PHP版本5.3

// read the post from PayPal system and add 'cmd'
$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.1\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Host: www.paypal.com\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n";
$header .= "Connection: close\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);
//$res = trim($res); //NEW & IMPORTANT 
if (strcmp (trim($res), 'VERIFIED') == 0){

}
else if (strcmp (trim($res), "INVALID") == 0) {
// log for manual investigation
}
}
fclose ($fp);
}

(我仍然无法从Paypal获得'验证'回复) 有什么建议吗?

0 个答案:

没有答案