gpt4 book ai didi

paypal - 根据文档,IPN Listener 的示例代码不正确。是吗?

转载 作者:太空宇宙 更新时间:2023-11-03 16:24:28 24 4
gpt4 key购买 nike

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&notify_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&notify_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&notify_version=2.1&custom=xyz123&invoice=abc1234&test_ipn=1&verify_sign=AFcWxV21C7fd0v3bYYYRCpSSRl31Ag-J5Edcf2.K.Ii9C6RoBck3ltT5]

最佳答案

根据我多年运行基于 Java servlet 的 IPN 监听器的经验,验证消息中参数的顺序没有丝毫区别,这与 IPN 文档中的许多声明相反。

Paypal 提供了用于从 servlet 发送验证消息的 Java 代码,而 Java servlet 无法按照参数最初发送的顺序访问参数,这也证明了这一点。

编辑 注意这是无效的:

strRequest = [&cmd=_notify-validate&payment_type=instant&payment_date=...

POST 参数不应以& 开头。它是名称-值对之间的分隔符。

关于paypal - 根据文档,IPN Listener 的示例代码不正确。是吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38391331/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com