提交Paypal页面:
<form target="_self" action="https://www.paypal.com/cgi-bin/webscr" method="post" name="E_FORM"> <input type="hidden" name="add" value="1"> <input type="hidden" name="cmd" value="_xclick"> <%--_xclick代表已做好购物车--%> <input type="hidden" name="business" value="<%= business %>"> <%--付入帐户--%> <input type="hidden" name="item_name" value="<%= item_name %>"> <%--名称/可以是订单号--%> <input type="hidden" name="item_number" value="<%= item_number %>"> <%--可以记录其他信息,如用户ID等--%> <input type="hidden" name="amount" value="<%= amount %>"> <%--金额--%> <input type="hidden" name="no_note" value="1"> <input type="hidden" name="quantity" value="1"> <%--数量--%> <input type="hidden" name="currency_code" value="USD"> <%--币种--%> <input type="hidden" name="bn" value="PP-BuyNowBF"> <input type="hidden" name="rm" value="2"> <%--值为2时,支付完成返回值--%> <input type="hidden" name="return" value="http://"> <%--返回页面--%> </form> |
更多提交变量可以参考Paypal官方网站:
https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_Appx_websitestandard_htmlvariables
接收Paypal返回值:
Request.Form["payment_status"].ToString().Trim(); 返回支付状态:Completed 代表支付成功。 Request.Form["item_name"].ToString().Trim(); 就是提交时的 item_name Request.Form["item_number"].ToString().Trim(); 就是提交时的 item_number Request.Form["business"].ToString().Trim(); 就是付入帐户,正常情况提交时的 business Request.Form["verify_sign"].ToString().Trim(); 加密串 Request.Form["payment_gross"].ToString().Trim(); 总支付金额 Request.Form["mc_currency"].ToString().Trim(); 币种 |
更多接收变量可以参考Paypal官方网站:
https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_IPNandPDTVariables
或我的博客: http://blog.sina.com.cn/s/blog_5e06afe00100ehjx.html
下面是验证支付的真实性:
private bool VerifyIPN() { string strFormValues = Request.Form.ToString(); string strNewValue; string strResponse; string serverURL = "https://www.sandbox.paypal.com/cgi-bin/webscr"; HttpWebRequest req = (HttpWebRequest)WebRequest.Create(serverURL); req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded"; strNewValue = strFormValues + "&cmd=_notify-validate"; req.ContentLength = strNewValue.Length; StreamWriter stOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII); stOut.Write(strNewValue); stOut.Close(); StreamReader stIn = new StreamReader(req.GetResponse().GetResponseStream()); strResponse = stIn.ReadToEnd(); stIn.Close(); return strResponse == "VERIFIED"; } |