Paypal IPN验证拒绝访问 [英] Access Denied on Paypal IPN verification

查看:628
本文介绍了Paypal IPN验证拒绝访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用IPN验证付款时出现以下错误。在沙盒上测试了相同的代码(错误之前和之后),并正确验证。

I'm getting the the following error when trying to verify payments using the IPN. The same code was tested on the sandbox (before and after the error) and is verifying properly.

<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,并进行了四个小时的调试。

I'm on Ubuntu 14.04, with openssl, curl and phpcurl installed, and four hours of debugging.

推荐答案

在与PayPal技术支持人员交谈后,最后找到了解决方案。这是一个问题,他们已经改变,并正在努力解决,但要让它再工作你只需要发送一个User-AgentHTTP头与Curl请求,如下:

Finally found the fix for this after speaking with PayPal Technical Support. It was an issue with something they have changed and are working to fix but to get it to work again you simply have to send a "User-Agent" HTTP Header with the Curl request, so something like:

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

至于User-Agent应该设置为什么,它只需要至少5个字符,可能是您的公司名称作为示例显示,但它不一定是。

As for what the "User-Agent" should be set as, it just needs to be at least 5 characters, probably your company name as the example shows but it doesn't have to be.

技术支持代理也指向我:
https://ppmts.custhelp.com/app/answers/detail/a_id/92
如果上面的修复不工作,但它为我。

The Technical Support agent also pointed me to: https://ppmts.custhelp.com/app/answers/detail/a_id/92 if the above fix does not work, but it did for me.

这篇关于Paypal IPN验证拒绝访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆