2012-10-29 76 views
4

我将PayPal与IPN集成在一起(我曾在很多网站上完成此操作,之前从未遇到过这个问题。)我使用PHP Paypal IPN集成类 - Micah Carrick。IPN验证失败

我正在沙盒帐户上测试它。 我从贝宝收到的所有数据都没有问题。但总是IPN验证失败。

我在很多项目上都使用过相同的类,但从来没有遇到过这个问题,请指导我,这个问题可能是什么原因。

这是我在日志文件中我得到:

[10/29/2012 5:02 AM] - FAIL: IPN Validation Failed. 
IPN POST Vars from Paypal: 
mc_gross=10.00, protection_eligibility=Eligible, address_status=confirmed, payer_id=LZ3J5RXT7ZRSW, tax=0.00, address_street=1 Main St, payment_date=03:02:41 Oct 29, 2012 PDT, payment_status=Completed, charset=windows-1252, address_zip=95131, first_name=AProfessionals, mc_fee=0.59, address_country_code=US, address_name=AProfessionals Inc, notify_version=3.7, custom=, payer_status=verified, [email protected], address_country=United States, address_city=San Jose, quantity=1, verify_sign=AV0bkFkV43dlmXuqlWjyHTfWE.SBANTBgLiHNABcsVQsMvyhdLQg8mTi, [email protected], txn_id=9ES74523RB953760X, payment_type=instant, last_name=Inc, address_state=CA, [email protected], payment_fee=0.59, receiver_id=NEV59MNUMBET6, txn_type=web_accept, item_name=Paypal Test Transaction, mc_currency=USD, item_number=, residence_country=US, test_ipn=1, handling_amount=0.00, transaction_subject=Paypal Test Transaction, payment_gross=10.00, shipping=0.00, ipn_track_id=74d5b2446aded, 

IPN Response from Paypal Server: 
HTTP/1.0 302 Found 
Location: https://www.sandbox.paypal.com 
Server: BigIP 
Connection: close 
Content-Length: 0 
+0

我试着IPN模拟器来检查问题,我在我的日志文件中得到这个错误:[29-Oct-2012 11:24:51 UTC] cURL错误:[77]问题与SSL CA证书(路径?访问权利?) –

+1

您是否在请求中使用“主机”标题?你有没有看到贝宝的这个通知? https://www.x.com/developers/community/blogs/pp_mts_robertg/action-required-update-your-ipn-pdt-scripts – dbellizzi

+0

今天刚刚面临同样的问题。解决这篇文章:http://stackoverflow.com/questions/11746644/paypal-sandbox-ipn-always-returns-invalid/37630831#37630831 – Naguissa

回答

3

从我的经验这就是为什么IPN验证失败

1)cmd=_notify-validate是附加的而不是前面加上3个常见的原因......这有时会造成问题。因此,而不是:

$post_string = '';  
    foreach ($_POST as $field=>$value) { 
    $this->ipn_data["$field"] = $value; 
    $post_string .= $field.'='.urlencode(stripslashes($value)).'&'; 
    } 
    $post_string.="cmd=_notify-validate"; // append ipn command 

按照代码此页上:https://www.x.com/developers/PayPal/documentation-tools/code-sample/216623

// read the post from PayPal system and add 'cmd' 
$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"; 
} 

2)地址是多衬里。

// read post data from PayPal and add 'cmd' 
$req = 'cmd=_notify-validate'; 
foreach ($_POST as $key => $value) 
{ 
    // put line feeds back to CR+LF as that's how PayPal sends them out 
    // otherwise multi-line data will be rejected as INVALID 
    $value = str_replace("\n", "\r\n", $value); 
     $this->ipn_data_arr[$key] = $value; 
     $req .= '&'.$key.'='.urlencode(stripslashes($value)); 
    } 

您可以去您的PayPal ACC,并从1号线更改为2线和使用ACC办理测试这个自己。 2号线惨遭失败,但不会$value = str_replace("\n", "\r\n", $value);大家都知道为什么贝宝并没有在他们的示例代码行...

3)用户在他们的姓名,地址非英文字符等(可能并不适用于你,但因为我们的话题)

看到:http://blog.tentaclesoftware.com/archive/2010/04/09/87.aspx 的主要观点是:

Log into PayPal 
Click the ‘Profile’ link in the menu bar under ‘My Account’ 
Click the ‘Language Encoding’ link under the ‘Selling Preferences’ column 
Click ‘More Options’ 
Set ‘Encoding’ to ‘UTF-8’ 
Click ‘Save’ 

如果您发现有在所有3一个共同的主题:数据的顺序,数据的编码,如果只是一件小事情略有不同,它会失败。所以如果不是这三个理由,请按照这些思路来思考。查找并检查该字段其数据将有可能导致问题......非标准的字符,隐元数据等

+0

代码示例移动到http://paypal.github.io/sdk/sample -apps/ espcially https://github.com/paypal/ipn-code-samples – staabm

2

在贝宝的库而改变一件事

//打开连接到PayPal

$fp = fsockopen(‘ssl://’.$url_parsed[host],“443”,$err_num,$err_str,30); 

//$fp = fsockopen($url_parsed[host],“80”,$err_num,$err_str,30);