PHP/CodeIgniter PayPal IPN无效验证



我正在CodeIgniter2上构建一个网站,我正在使用CodeIgniter PayPal Lib。我已经做了一切必要的事情,现在我可以继续付款了。我收到一个IPN数据,并将其发送到我的电子邮件中。我已经阅读了PayPal IPN指南,但我在那里找不到解决方案。

直到现在一切都很好,我对结果很满意,但我很担心,因为PayPal IPN验证失败,我无法理解问题出在哪里。

当我从沙盒测试网站发送IPN测试时,我会收到一个有效的IPN,,但当我从我的网站付款时,IPN验证失败。

我正在记录所有数据,在这两种情况下(有效或无效)付款都是成功的,我收到了来自PayPal的"成功!"消息。

我尝试过的东西

  1. 打开/关闭CSRF保护
  2. 更改编码(utf-8|windows-1252)
  3. 添加|从我的PayPal请求中删除字段

我正在使用的代码

我正在使用的字段

$this->paypal_lib->add_field('business', 'name_1321715512_biz@gmail.com');
$this->paypal_lib->add_field('return', site_url('paypal/success'));
$this->paypal_lib->add_field('cancel_return', site_url('paypal/cancel'));
$this->paypal_lib->add_field('notify_url', site_url('contest/receive_ipn'));
$this->paypal_lib->add_field('item_name', 'Contest Subscribtion Payment (Test)');
$this->paypal_lib->add_field('amount', '30');
$this->paypal_lib->add_field('item_number', Y11-1329469079-12); // Reference number
$this->paypal_lib->add_field('quantity', '1');
$this->paypal_lib->add_field('charset', 'utf8');
$this->paypal_lib->add_field('custom', 1723); //This is an id that I need.  

张贴到PayPal验证

$post_string.="cmd=_notify-validate";
if (isset($_POST)){
    foreach ($_POST as $field=>$value){
         $value = str_replace("n", "rn", $value);
         $value = urlencode(stripslashes($value));
         $post_string .= "&$field=$value";
         $this->ipn_data[$field] = $value; //this is part of the library
    }
}
$header .= "POST /cgi-bin/webscr HTTP/1.0rn";
$header .= "Content-Type: application/x-www-form-urlencodedrn";
$header .= "Content-Length: " . strlen($post_string) . "rnrn";
$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);

验证IPN 的代码

fputs ($fp, $header . $post_string);
while (!feof($fp)) {
    $res = fgets ($fp, 1024);
    if (strcmp ($res, "VERIFIED") == 0) {
        // Send me e-mail - Verified
    } else if (strcmp ($res, "INVALID") == 0) {
        // Send me e-mail - Invalid
    }
}
fclose($fp);

我还发布了收到的回复

这是无效的(然后从我的网站发送)

cmd=_notify-validate&mc_gross=30.00&protection_eligibility=Ineligible&address_status=unconfirmed&payer_id=LD9UMUWHD44GY&tax=0.00&address_street=Via+Unit+d%27Italia%2C+5783296&payment_date=02%3A19%3A29+Feb+17%2C+2012+PST&payment_status=Completed&charset=windows-1252&address_zip=80127&first_name=Alexander&mc_fee=1.37&address_country_code=IT&address_name=Alexander+Videnov&notify_version=3.4&custom=1721&payer_status=verified&business=aviden_1321715512_biz%40gmail.com&address_country=Italy&address_city=Napoli&quantity=1&verify_sign=AF1YwvTycK97c-VCwQnfsdzArWAcAqZjskElh-FsmZ0s9HqL9BjFUKVH&payer_email=aviden_1329133801_per%40gmail.com&txn_id=32Y96385XJ0686735&payment_type=instant&last_name=Videnov&address_state=Napoli&receiver_email=aviden_1321715512_biz%40gmail.com&payment_fee=&receiver_id=TQVQ3ASRDBW28&txn_type=web_accept&item_name=Yicca+Contest+Subscribtion+Payment+%28Test%29&mc_currency=EUR&item_number=Y11-1329473936-12&residence_country=IT&test_ipn=1&handling_amount=0.00&transaction_subject=1721&payment_gross=&shipping=0.00&ipn_track_id=35382e1887f00

这是经过验证的(当从PayPal测试网站发送时)

cmd=_notify-validate&test_ipn=1&payment_type=echeck&payment_date=02%3A28%3A24+Feb+17%2C+2012+PST&payment_status=Completed&address_status=confirmed&payer_status=verified&first_name=John&last_name=Smith&payer_email=buyer%40paypalsandbox.com&payer_id=TESTBUYERID01&address_name=John+Smith&address_country=United+States&address_country_code=US&address_zip=95131&address_state=CA&address_city=San+Jose&address_street=123%2C+any+street&business=seller%40paypalsandbox.com&receiver_email=seller%40paypalsandbox.com&receiver_id=TESTSELLERID1&residence_country=US&item_name=something&item_number=AK-1234&quantity=1&shipping=3.04&tax=2.02&mc_currency=USD&mc_fee=0.44&mc_gross=12.34&txn_type=web_accept&txn_id=242171028&notify_version=2.1&custom=xyz123&invoice=abc1234&charset=windows-1252&verify_sign=An5ns1Kso7MWUdW4ErQKJJJ4qi4-Arge8MWjXZSo7fPSQf3xaqAOjrSH

我注意到两件事

  1. 字段(请求)的顺序在我的网站发送的IPN请求和从沙箱测试站点发送的请求之间是不同的
  2. notify_version字段存在差异。来自我的网站(3.4)|来自PayPal(2.1)

有人在验证时遇到过同样的问题吗。是否有我遗漏的东西,或者我可以调试更多的方法?

我收到了Paypal的回复,这可能也与您有关:

现在我们从经验中知道,在IPN验证过程中,特殊字符可能很难处理。基本上,我们用于向您的服务器发送IPN消息的字符编码需要由您的IPN处理程序在将消息发布回PayPal系统进行验证时进行匹配。

通过将帐户的语言编码选项更改为UTF-8,我们在解决这些问题方面取得了很大成功。

以下是您的操作方法:1.请登录您的PayPal帐户。

  1. 然后点击此链接,直接进入语言编码选项:https://www.paypal.com/cgi-bin/webscr?cmd=_profile-语言编码

  2. 单击"更多选项"按钮。

  3. 将两个下拉菜单都更改为UTF-8,然后单击保存。

如果您在代码中指定了不同的字符编码,请将其切换为UTF-8。

不确定是否使用自适应支付,但我使用了这个库:http://www.binpress.com/app/paypal-adaptive-payments-pro-codeigniter-library/140它非常棒,作者也很有帮助。

请参阅我的问题:Paypal IPN问题与平行支付。我已经在答案中发布了我的贝宝IPN代码。

CodeIgniter PayPal Lib已经过时,并且一直存在错误。至少根据我的经验。

我所做的,也是我建议的,是使用官方的PayPal SDK并将其"转换"为CI。这相当容易。

你可以在这里找到这些:https://cms.paypal.com/us/cgi-bin/?cmd=_render-内容&content_ID=开发人员/library_download_sdks

还要查看文档:https://www.x.com/developers/paypal/development-integration-guides#ec没有他们你就活不下去!

最新更新