PayPal 沙盒 IPN 验证始终 return 无效

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 字段中......(鼓声...... tadam!)!不,它的值必须与 IPN 发送给您的值相同,但是……大写! IPN 以小写形式发送!因此,您必须修改 IPN 数据以验证它是否成功,无论手册告诉我们 return 数据返回 "as-is"。贝宝错误?

所以我最终的工作代码是:(使用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 没有一些 IPN 字段,例如 authverify_signtest_ipn。但所有其他领域似乎必须相同。唯一的区别在于 charset 字段的字符大小写。然后我尝试验证修改后的数据,没想到竟然成功了!

这是最近的 PayPal 错误,当客户完成付款并点击 "Click here to return.." 而不是等待几秒钟时,传递给您网站上的 PDT 脚本的参数将以小写形式发送。

这也会弄乱区分大小写或编码的 cm/custom 参数。

显然 PayPal 知道这一点。