我在尝试使用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,并进行了四个小时的调试。
在与PayPal技术支持人员交谈后,终于找到了解决方案。这是一个他们已经改变并正在努力解决的问题,但要让它再次工作,你只需要发送一个带有Curl请求的"用户代理"HTTP头,所以类似于:
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close', 'User-Agent: company-name'));
至于"用户代理"应该设置为什么,它只需要至少5个字符,可能是您的公司名称,如示例所示,但它不必是。
技术支持代理还向我指出:https://ppmts.custhelp.com/app/answers/detail/a_id/92如果上面的修复程序不起作用,但它对我起了作用。
我使用任何浏览器访问任何贝宝账户也被拒绝访问(403)。一旦发生,它就会继续发生。
对于Firefox和Safari,解决方案是搜索所有与PayPal相关的cookie并将其删除。问题消失了。
任何其他人通过谷歌搜索找到这个,我在访问任何Paypal URL时都遇到了类似的问题——我会得到"拒绝访问"。原因是用户代理问题——我有一个UA切换器扩展,使用的是带有非标准用户代理的Chrome。恢复到默认的用户代理解决了此问题。
如果有人在Android设备上遇到此问题,请尝试下载或重新下载"Internet和MMS设置"。
设置-网络-互联网设置
我想通过这样做,你可以重置或更新任何需要做的设置。为我的索尼Xperia Z2工作!