PayPal在this reference提供的示例代码明显与我能找到的所有代码示例相矛盾。特别是它需要"& cmd = _notify-validate"在开始而不是在结束。
以下代码传递第一个测试,即仅响应IPN模拟器中的请求。一旦添加了grunt代码,我得到的就是"未发送IPN,并且未验证握手。请检查您的信息。"响应。
我已尽可能多地评论以下代码:
protected void Page_Load(object sender, EventArgs e)
{
mclog.Info("entered PayPalListener Page_Load");
// Commenting out the rest results in a successful handshake etc with the IPN Simulator
string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr";
// string strLive = "https://www.paypal.com/cgi-bin/webscr";
mclog.Info(string.Format("strSandBox = [{0}]", strSandbox));
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strSandbox);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
byte[] param = Request.BinaryRead(HttpContext.Current.Request.ContentLength);
// The following string can have the cmd text at the beginning or end. Both cause the IPN to spit the dummy.
string strRequest = "&cmd=_notify-validate&";
strRequest += Encoding.ASCII.GetString(param);
// "&cmd=_notify-validate";
req.ContentLength = strRequest.Length;
mclog.Info(string.Format("strRequest = [{0}]", strRequest));
//Send the request to PayPal and get the response
StreamWriter streamOut =
new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
streamOut.Write(strRequest);
streamOut.Close();
StreamReader streamIn =
new StreamReader(req.GetResponse().GetResponseStream());
string strResponse = streamIn.ReadToEnd();
streamIn.Close();
mclog.Info(string.Format("strResponse = [{0}]", strResponse));
}
代码看起来是正确的,所以经过多次搜索后,我认为还有其他一些必须做的事情。提及"启用" IPN在我的"个人资料"但是,我可以在我的开发者帐户中找到的配置文件中没有这样的选项。
我一直在努力寻找日子,而挫折程度却达到了规模。如果您确实有一些建议,请尽可能详细,因为PayPal文档非常混乱,而且以前的好建议似乎已经过时了。
一些记录结果是:
2016-07-15 00:02:29:854 W15 INFO MyPayPal.PayPal.PayPalListener.Page_Load.0 entered PayPalListener Page_Load
2016-07-15 00:02:29:854 W15 INFO MyPayPal.PayPal.PayPalListener.Page_Load.0 Received
2016-07-15 00:02:29:870 W15 INFO MyPayPal.PayPal.PayPalListener.Page_Load.0 strSandBox = [https://www.sandbox.paypal.com/cgi-bin/webscr]
2016-07-15 00:02:29:870 W15 INFO MyPayPal.PayPal.PayPalListener.Page_Load.0 strRequest = [payment_type=instant&payment_date=Fri%20Jul%2015%202016%2016%3A32%3A05%20GMT+0930%20%28Cen.%20Australia%20Standard%20Time%29&payment_status=Completed&address_status=confirmed&payer_status=verified&first_name=John&last_name=Smith&payer_email=buyer@paypalsandbox.com&payer_id=TESTBUYERID01&address_name=John%20Smith&address_country=United%20States&address_country_code=US&address_zip=95131&address_state=CA&address_city=San%20Jose&address_street=123%20any%20street&business=seller@paypalsandbox.com&receiver_email=seller@paypalsandbox.com&receiver_id=seller@paypalsandbox.com&residence_country=US&item_name1=something&item_number1=AK-1234&tax=2.02&mc_currency=USD&mc_fee=0.44&mc_gross=12.34&mc_gross_1=12.34&mc_handling=2.06&mc_handling1=1.67&mc_shipping=3.02&mc_shipping1=1.02&txn_type=cart&txn_id=636818821¬ify_version=2.1&custom=xyz123&invoice=abc1234&test_ipn=1&verify_sign=AneSo.zKXXEtrcrzCxSU.y9TEUb1A9u2e-FoPLwAA6kE8qMzV0UNUYV5]
2016-07-15 00:02:29:870 W15 INFO MyPayPal.PayPal.PayPalListener.Page_Load.0 strRequest = [payment_type=instant&payment_date=Fri%20Jul%2015%202016%2016%3A32%3A05%20GMT+0930%20%28Cen.%20Australia%20Standard%20Time%29&payment_status=Completed&address_status=confirmed&payer_status=verified&first_name=John&last_name=Smith&payer_email=buyer@paypalsandbox.com&payer_id=TESTBUYERID01&address_name=John%20Smith&address_country=United%20States&address_country_code=US&address_zip=95131&address_state=CA&address_city=San%20Jose&address_street=123%20any%20street&business=seller@paypalsandbox.com&receiver_email=seller@paypalsandbox.com&receiver_id=seller@paypalsandbox.com&residence_country=US&item_name1=something&item_number1=AK-1234&tax=2.02&mc_currency=USD&mc_fee=0.44&mc_gross=12.34&mc_gross_1=12.34&mc_handling=2.06&mc_handling1=1.67&mc_shipping=3.02&mc_shipping1=1.02&txn_type=cart&txn_id=636818821¬ify_version=2.1&custom=xyz123&invoice=abc1234&test_ipn=1&verify_sign=AneSo.zKXXEtrcrzCxSU.y9TEUb1A9u2e-FoPLwAA6kE8qMzV0UNUYV5&cmd=_notify-validate]
2016-07-15 00:45:09:012 W15 INFO MyPayPal.Global.createMCLog.0 ###################################
2016-07-15 00:45:09:106 W15 INFO MyPayPal.Global.createMCLog.0 MyPayPal v1.0.0.0 Startup
2016-07-15 00:45:12:700 W15 INFO MyPayPal.PayPal.PayPalListener.Page_Load.0 entered PayPalListener Page_Load
2016-07-15 00:45:12:715 W15 INFO MyPayPal.PayPal.PayPalListener.Page_Load.0 strSandBox = [https://www.sandbox.paypal.com/cgi-bin/webscr]
2016-07-15 00:45:12:778 W15 INFO MyPayPal.PayPal.PayPalListener.Page_Load.0 strRequest = [&cmd=_notify-validate&]
2016-07-15 00:45:12:778 W15 INFO MyPayPal.PayPal.PayPalListener.Page_Load.0 strRequest = [&cmd=_notify-validate&payment_type=instant&payment_date=Fri%20Jul%2015%202016%2017%3A14%3A51%20GMT+0930%20%28Cen.%20Australia%20Standard%20Time%29&payment_status=Completed&address_status=confirmed&payer_status=verified&first_name=John&last_name=Smith&payer_email=buyer@paypalsandbox.com&payer_id=TESTBUYERID01&address_name=John%20Smith&address_country=United%20States&address_country_code=US&address_zip=95131&address_state=CA&address_city=San%20Jose&address_street=123%20any%20street&business=seller@paypalsandbox.com&receiver_email=seller@paypalsandbox.com&receiver_id=seller@paypalsandbox.com&residence_country=US&item_name1=something&item_number1=AK-1234&tax=2.02&mc_currency=USD&mc_fee=0.44&mc_gross=12.34&mc_gross_1=12.34&mc_handling=2.06&mc_handling1=1.67&mc_shipping=3.02&mc_shipping1=1.02&txn_type=cart&txn_id=952340474¬ify_version=2.1&custom=xyz123&invoice=abc1234&test_ipn=1&verify_sign=AFcWxV21C7fd0v3bYYYRCpSSRl31Ag-J5Edcf2.K.Ii9C6RoBck3ltT5]
答案 0 :(得分:1)
根据我多年来运行基于Java servlet的IPN监听器的经验,验证消息中的参数顺序没有丝毫差别,这与IPN文档中的众多声明相反。 / p>
Paypal提供了用于从servlet发送验证消息的Java代码,并且Java servlet无法按照它们首先发送的顺序访问参数,这也证明了这一点。 / p>
编辑 NB这是无效的:
strRequest = [&cmd=_notify-validate&payment_type=instant&payment_date=...
POST参数不应以&
开头。它是名称 - 值对之间的分隔符。