0
我正在使用該文章與PayPal一起玩(http://www.codeproject.com/Articles/42894/Introduction-to-PayPal-for-C-ASP-NET-developers)。MVC 3 PayPal IPN響應始終無效
後,貝寶(沙盒)支付完成後,我回到我的瀏覽與查詢字符串:
tx=9S599242S3646572T&st=Completed&amt=9.00&cc=AUD&cm=Registration+started%3a+2012-03-10+18%3a33%3a27&item_number=
使用代碼
authToken = WebConfigurationManager.AppSettings["PDTToken"];
txToken = Request.QueryString.Get("tx");
query = string.Format("cmd=_notify-synch&tx={0}&at={1}",
txToken, authToken);
string url = WebConfigurationManager.AppSettings["PayPalSubmitUrl"];
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = query.Length;
StreamWriter stOut = new StreamWriter(req.GetRequestStream(),
System.Text.Encoding.ASCII);
stOut.Write(query);
stOut.Close();
StreamReader stIn = new StreamReader(req.GetResponse().GetResponseStream());
strResponse = stIn.ReadToEnd();
stIn.Close();
PayPal的響應與類似的東西:
SUCCESS
first_name=Firstname
last_name=Lastname
payment_status=Completed
payer_email=firstname%40lastname.com
payment_gross=50.00
mc_currency=USD
custom=Custom+value+you+passed+with+your+HTML+form
etc.
好,但(可能基於該ersponse)我想驗證事務s Ø我用下面的代碼(那篇文章所)
string postUrl = ConfigurationManager.AppSettings["PayPalSubmitUrl"];
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(postUrl);
//Set values for the request back
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
byte[] param = Request.BinaryRead(HttpContext.Current.Request.ContentLength);
string strRequest = Encoding.ASCII.GetString(param);
string ipnPost = strRequest;
strRequest += "&cmd=_notify-validate";
req.ContentLength = strRequest.Length;
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();
但HttpContext.Current.Request.ContentLength
是0,所以我總是得到INVALID
響應。難道我做錯了什麼 ?
不,您提供的解決方案也無效。也沒有HttpContext.Current.Request,有HttpContext.Request – Tony 2012-03-21 13:31:54