IPN验证失败

时间:2012-10-29 10:10:03

标签: php paypal paypal-ipn

我正在将paypal与IPN集成,(我在很多网站上都做过这个,之前从未遇到过这个问题。)我正在使用PHP Paypal IPN集成类 - Micah Carrick。

我正在沙盒帐户上测试它。 我从paypal收到的所有数据都很好。但总是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, business=brian_1351496665_biz@a1professionals.com, address_country=United States, address_city=San Jose, quantity=1, verify_sign=AV0bkFkV43dlmXuqlWjyHTfWE.SBANTBgLiHNABcsVQsMvyhdLQg8mTi, payer_email=harry_1351496900_per@a1professionals.com, txn_id=9ES74523RB953760X, payment_type=instant, last_name=Inc, address_state=CA, receiver_email=brian_1351496665_biz@a1professionals.com, 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

2 个答案:

答案 0 :(得分:3)

根据我的经验,这些是IPN验证失败的3个常见原因

1)cmd=_notify-validate被追加而不是前置......这有时会引起问题。所以而不是:

  $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进行交易来自行测试。没有$value = str_replace("\n", "\r\n", $value);的情况下,2行失败了我们都不知道为什么paypal在他们的示例代码中没有那行......

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中都有一个共同的主题:数据的顺序,数据的编码等,如果只是一个小的东西略有不同,它将失败。因此,如果不是这三个原因,请按照这些思路思考。查找并检查其数据可能导致问题的字段...非标准字符,隐藏元数据等

答案 1 :(得分:2)

在paypal库中改变了一件事

//打开与paypal的连接

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

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