我有一个可以运行的 IPN 脚本,并且已经工作了一段时间。最近我开始得到一个HTTP/1.1 302 Moved Temporarily
作为回应,无法确定原因。
以下是与发布到 PayPal 并获取响应相关的代码:
$sd = @fsockopen('ssl://www.paypal.com', 443, $errno, $errstr, 30);
if(!$sd) {
$error = 'Error opening socket connection to PayPal: '.$errstr;
quit($error, $errno);
}
$req = 'cmd=_notify-validate';
foreach($_POST as $key=>$value) $req .= "&{$key}=".urlencode(stripslashes($value));
// post back to PayPal to validate
$header = "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: ".strlen($req)."\r\n";
$header .= "Host: http://www.paypal.com/\r\n";
$header .= "Connection: close\r\n\r\n";
fputs($sd, $header.$req);
$response = '';
while(!feof($sd)) $response .= fgets($sd, 4096);
fclose($sd);
请注意,所有连接、传输和响应均有效,但我没有收到错误消息。但 PayPal 的响应并不正确,因为它没有提供其文档中所述的 VERIFIED 或 INVALID,而是提供 HTTP 302 错误。
我以这种方式构建我的请求(并且它有效)。也许它可以帮助你
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
//Fixes some special characters Paypal sends
$value = preg_replace('/(.*[^%^0^D])(%0A)(.*)/i','${1}%0D%0A${3}', $value);
$req .= '&' . $key . '=' . $value;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)