编程语言
首页 > 编程语言> > php – Paypal IPN验证拒绝访问

php – 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头,如下所示:

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

至于应该将“用户代理”设置为什么,它只需要至少5个字符,可能是您的公司名称,如示例所示,但不一定如此.

技术支持代理人还指出:
https://ppmts.custhelp.com/app/answers/detail/a_id/92
如果上述修复不起作用,但它确实适合我.

标签:php,curl,paypal-ipn
来源: https://codeday.me/bug/20190713/1449593.html