【发布时间】:2014-11-09 08:14:24
【问题描述】:
我在尝试使用 IPN 验证付款时遇到以下错误。相同的代码在沙盒上进行了测试(错误前后),并且正在正确验证。
<HTML>
<HEAD>
<TITLE>Access Denied</TITLE>
</HEAD>
<BODY>
<H1>Access Denied</H1>
You don't have permission to access "https://www.paypal.com/cgi-bin/webscr" on this server.<P>
Reference #18.........
</BODY>
</HTML>
我使用的代码如下:
$raw_post_data = file_get_contents('php://input');
pplog("Processing POSTed data");
$raw_post_array = explode('&', $raw_post_data);
$myPost = array();
foreach ($raw_post_array as $keyval) {
$keyval = explode ('=', $keyval);
if (count($keyval) == 2)
$myPost[$keyval[0]] = urldecode($keyval[1]);
}
// read the IPN message sent from PayPal and prepend 'cmd=_notify-validate'
$req = 'cmd=_notify-validate';
if(function_exists('get_magic_quotes_gpc')) {
$get_magic_quotes_exists = true;
}
foreach ($myPost as $key => $value) {
if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) {
$value = urlencode(stripslashes($value));
} else {
$value = urlencode($value);
}
$req .= "&$key=$value";
}
$ch = curl_init("https://www.paypal.com/cgi-bin/webscr");
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
if(!($res = curl_exec($ch)) ) {
error_log("Got " . curl_error($ch) . " when processing IPN data");
curl_close($ch);
exit;
}
curl_close($ch);
log($res);
我在 Ubuntu 14.04 上,安装了 openssl、curl 和 phpcurl,并进行了四个小时的调试。
【问题讨论】:
-
自 9 月 9 日以来我遇到了同样的问题。我认为 Paypal 改变了一些东西,但我到现在都找不到。
-
@Onur Yılmaz - 是的,他们做到了。您必须在您的 POST 中添加一个 USER AGENT 标头到贝宝。您可以为 USER-AGENT 设置任何您想要的内容。
-
@GRSEV 非常感谢。 :) 现在可以使用了。
-
Rob O'Brien 指出了这一点,谢谢!
标签: php curl paypal-ipn