PayPal沙箱IPN验证总是返回INVALID


PayPal sandbox IPN validation always return INVALID

我在谷歌上搜索了这个问题,并尝试了所有建议,但都没有效果。

我试过这个代码:https://developer.paypal.com/docs/classic/ipn/ht_ipn/但它不工作。只需复制粘贴并删除旧的magick_quotes例程。

我试过这个代码:http://samples.geekality.net/view-source.php?file=ipn/ipn_handler.class.php,它也不工作。

在所有情况下,我都试着这样做:

$req = 'cmd=_notify-validate&' . file_get_contents('php://input');

确保我发送给IPN 的内容与它发送给我的内容完全相同。此外,我使用调试代理(Fiddler)并保存IPN发送给我的内容和我发送给IPN的内容。请求体是字节到字节的相同,除了我的请求是由cmd=_notify-validate&字符串前缀。

是的,我检查了我使用正确的沙箱URL。以下是完整的请求正文:

IPN发给我的:(我刚刚把个人资料换成了XXX)

POST http://localhost.loc/en/payment/success/1 HTTP/1.1
Host: localhost.loc
Connection: keep-alive
Content-Length: 921
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Origin: null
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.81 Safari/537.36
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4
mc_gross=1.00&protection_eligibility=Ineligible&payer_id=5XNKM66NSDKC4&tax=0.00&payment_date=05%3A34%3A11+Jun+01%2C+2015+PDT&payment_status=Completed&charset=utf-8&first_name=XXX&mc_fee=0.33&notify_version=3.8&custom=topup%3A262262%3A1%3A1433162020&payer_status=verified&business=XXX&quantity=1&payer_email=XXX&verify_sign=AG58dBsn5g2z8O8NEjotbuJGP14PAIpZ4k26VL8IyhaDPkcDRj002Keq&memo=hmgvjgjhgfjhfggjhfjtfgjh&txn_id=4CN141026K278934Y&payment_type=instant&last_name=XXX&receiver_email=XXX&payment_fee=0.33&receiver_id=DCMXPXGX4QX6J&txn_type=web_accept&item_name=Account+top+up&mc_currency=USD&item_number=Account+262262+top+up&residence_country=US&test_ipn=1&handling_amount=0.00&transaction_subject=topup%3A262262%3A1%3A1433162020&payment_gross=1.00&shipping=0.00&auth=ANSTBwT3znll-gJQZO2cLoV5QJFW9v8W.FqyWxffdtI0L-9mfsoe2xRL44M86Sn2XtYGtcqG4Fjjel1kdYZyxpQ

我发送给IPN的内容:

POST https://www.sandbox.paypal.com/cgi-bin/webscr HTTP/1.1
Host: www.sandbox.paypal.com
Accept: */*
Content-Length: 942
Content-Type: application/x-www-form-urlencoded
cmd=_notify-validate&mc_gross=1.00&protection_eligibility=Ineligible&payer_id=5XNKM66NSDKC4&tax=0.00&payment_date=05%3A34%3A11+Jun+01%2C+2015+PDT&payment_status=Completed&charset=utf-8&first_name=XXX&mc_fee=0.33&notify_version=3.8&custom=topup%3A262262%3A1%3A1433162020&payer_status=verified&business=XXX&quantity=1&payer_email=XXX&verify_sign=AG58dBsn5g2z8O8NEjotbuJGP14PAIpZ4k26VL8IyhaDPkcDRj002Keq&memo=hmgvjgjhgfjhfggjhfjtfgjh&txn_id=4CN141026K278934Y&payment_type=instant&last_name=XXX&receiver_email=XXX&payment_fee=0.33&receiver_id=DCMXPXGX4QX6J&txn_type=web_accept&item_name=Account+top+up&mc_currency=USD&item_number=Account+262262+top+up&residence_country=US&test_ipn=1&handling_amount=0.00&transaction_subject=topup%3A262262%3A1%3A1433162020&payment_gross=1.00&shipping=0.00&auth=ANSTBwT3znll-gJQZO2cLoV5QJFW9v8W.FqyWxffdtI0L-9mfsoe2xRL44M86Sn2XtYGtcqG4Fjjel1kdYZyxpQ
谁能告诉我我做错了什么?谢谢。

AARRRRGH!!!!!!!!我对PayPal只有脏话!!!!!!!问题出在……(击鼓声…)在charset领域!不,它的值必须和IPN发给你的一样,但是…在大写!IPN以小写形式发送!所以你必须修改IPN数据来验证它是否成功,不管手册告诉我们"按原样"返回数据。贝宝错误?

所以我的最终工作代码是:(使用HTTP_Request2)
protected function verifyPostData() {
    $this->request->setBody('cmd=_notify-validate&' . str_replace('=utf-8', '=UTF-8', file_get_contents('php://input')));
    $response = $this->request->send();
    if ($response->getStatus() != 200) {
        throw new 'RuntimeException("Transaction data verification request failed with code {$response->getStatus()}");
    }
    $content = trim($response->getBody());
    return ($content == 'VERIFIED');
}

我是怎么做的:我为这个事务发送了PDT请求,并获得了事务数据。然后我对PDT和IPN数据进行了实地对比。PDT中没有authverify_signtest_ipn等IPN域。但所有其他领域似乎都是一样的。唯一的区别是charset字段的字符大小写。然后我尝试验证修改后的数据,竟然成功了!

这是PayPal最近的一个错误,当客户完成支付并点击"点击这里返回.."而不是等待几秒钟,传递给您网站上的PDT脚本的参数以小写形式发送。

这也会混淆大小写敏感或编码的cm/自定义参数。

PayPal显然意识到了这一点。