4

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

我正在沙盒帐户上对其进行测试。我从贝宝收到的所有数据都很好。但 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
4

2 回答 2

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 进行交易来自己测试这一点。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 中都有一个共同的主题:数据的顺序、数据的编码等,如果只有一件小事略有不同,它就会失败。因此,如果不是这三个原因,请按照这些思路思考。查找并检查其数据可能导致问题的字段...非标准字符、隐藏的元数据等

于 2013-01-12T03:14:39.780 回答
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); 
于 2014-06-05T13:11:31.010 回答