本文介绍了尽管回传正确,但贝宝IPN模拟器始终返回INVALID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在升级IPN以使用TLS,并始终在使用IPN Simulator时将INVALID回发

We're in the process of upgrading our IPN to use TLS and am consistently getting INVALID posted back when using the IPN Simulator

当请求进入侦听器时,它就会被记录下来.在数据返回贝宝之前,即会记录URL和数据.此信息如下.

Right as the request comes in to the listener, it is logged. Right before the data goes back to paypal, the URL and the data are logged. This info is below.

数据似乎没有问题.我什至使用diffmerge来识别没有区别,除了cmd = _notify-validate&

There appears to be nothing wrong with the data. I've even used diffmerge to identify that there are no differences except cmd=_notify-validate&

仅仅是 IPN模拟器永远不会返回有效的密码吗?

Is it just that the IPN Simulator doesn't ever return valid?

请求前的URL是:

https://www.sandbox.paypal.com/cgi-bin/webscr


发布的数据是


The posted data is

cmd=_notify-validate&payment_type=instant&payment_date=Mon May 23 2016 17:41:16 GMT 1000 (E. Australia Standard Time)&payment_status=Completed&address_status=confirmed&payer_status=verified&first_name=John&last_name=Smith&[email protected]&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 any street&[email protected]&[email protected]&[email protected]&residence_country=US&item_name=something&item_number=CHIMPREWRITER-LIFE&quantity=1&shipping=3.04&tax=2.02&mc_currency=USD&mc_fee=0.44&mc_gross=139&mc_gross_1=139&txn_type=web_accept&txn_id=928133899&notify_version=2.1&custom=xyz123&invoice=abc1234&test_ipn=1&verify_sign=AFcWxV21C7fd0v3bYYYRCpSSRl31AU-9VToMcj-IcSKMfmb8nz2kgIe.


贝宝(Paypal)的数据是


The data from Paypal is

payment_type=instant&payment_date=Mon May 23 2016 17:41:16 GMT 1000 (E. Australia Standard Time)&payment_status=Completed&address_status=confirmed&payer_status=verified&first_name=John&last_name=Smith&[email protected]&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 any street&[email protected]&[email protected]&[email protected]&residence_country=US&item_name=something&item_number=CHIMPREWRITER-LIFE&quantity=1&shipping=3.04&tax=2.02&mc_currency=USD&mc_fee=0.44&mc_gross=139&mc_gross_1=139&txn_type=web_accept&txn_id=928133899&notify_version=2.1&custom=xyz123&invoice=abc1234&test_ipn=1&verify_sign=AFcWxV21C7fd0v3bYYYRCpSSRl31AU-9VToMcj-IcSKMfmb8nz2kgIe.


供参考,代码为:


For reference, the code is:

// This was legacy code I was trying in case there were formatting problems. The code "cmd=_notify-validate&" + _request.Form; does some URL encoding which I thought might be causing problems. Either way, we still get INVALID
string s = "cmd=_notify-validate";
foreach (string paramName in _request.Form)
{
    string paramValue = LicServiceTools.Encode(_request.Form[paramName]);
    //s = s + string.Format("&{0}={1}", paramName, paramValue);
    s = s + string.Format("&{0}={1}", paramName, _request.Form[paramName]);
}

string address = "https://www.paypal.com/cgi-bin/webscr";
if (this.useSandBox)
{
    address = "https://www.sandbox.paypal.com/cgi-bin/webscr";
}
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(address);
req.ProtocolVersion = HttpVersion.Version11;
//Set values for the request back
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";

// ALSO DOESNT WORK
//string strRequest = "cmd=_notify-validate&" + _request.Form;
//req.ContentLength = strRequest.Length;

errorLogger.Info(s);
errorLogger.Info(address);

//Send the request to PayPal and get the response
StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
streamOut.Write(s);
streamOut.Close();
StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
string strResponse = streamIn.ReadToEnd();
streamIn.Close();

// at this point, strResponse = INVALID

推荐答案

由于时区中的"+",出现了新的IPN模拟器paying_date混乱的情况.实时通知似乎都没有列出这样的时区,因此先前的代码可以正常工作.

Turns out the new IPN Simulator payment_date messes things up, because of the "+" in the timezone. None of the live notifications seem to list the timezone like this, so the previous code was working.

此线程节省了一天的时间: https://github.com/paypal/ipn-code-samples/issues/51

This thread saved the day: https://github.com/paypal/ipn-code-samples/issues/51

这篇关于尽管回传正确,但贝宝IPN模拟器始终返回INVALID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 05:02