php - Paypal IPN 验证拒绝访问

标签 php curl paypal-ipn

我在尝试使用 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 请求的“User-Agent”HTTP header ,例如:

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close', 'User-Agent: company-name'));

至于“User-Agent”应该设置成什么,它至少需要5个字符,可能是你的公司名称,如示例所示,但不一定是。

技术支持代理还向我指出: https://ppmts.custhelp.com/app/answers/detail/a_id/92 如果上述修复不起作用,但它对我有用。

关于php - Paypal IPN 验证拒绝访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25854207/

相关文章:

javascript - 使用 php curl 进行长轮询

PHP curl 缓慢

node.js - 使用 node.js 进行 Paypal IPN 验证 - express 应用程序

Reversal 和 Canceled_Reversal 付款状态的 PayPal IPN

php - 有限制的用户列表

php - 每次我进行查询或从 <th> 标记排序时,对 sql 查询和 ID 重置进行排序并按数字顺序开始

iPhone 向左 curl 和向右 curl 过渡

php - 当用户首次通过 Paypal 重定向时,我如何获取传递的发布数据?

php - Laravel 4.2 Composer 安装错误 : "could not scan for classes"

php - 使用 AJAX 加载 PHP 页面是好习惯吗?