topaypal完成支付:因为我必须在将用户重定向到paypal之前做一些操作,所以我需要一个普通的asp按钮,它会做一些操作在将用户重定向到贝宝之前。我的问题是如何从c#codebehind做到这一点?重要的是我可以从上面的表单中传递所有必需的隐藏字段,如“自定义”。传统的ASP.Net不允许使用多个表单标签。以下示例代码将允许您从后面的代码将表单发布到PayPal。protectedvoidBuyButton_Click(objectsender,EventArgse){stringurl=TestMode?“https://www.sandbox.paypal.com/us/cgi-bin/webscr”:“https://www.paypal.com/us/cgi-bin/webscr”;varbuilder=newStringBuilder();建造者。追加(网址);builder.AppendFormat("?cmd=_xclick&business={0}",HttpUtility.UrlEncode(Email));builder.Append("&lc=US&no_note=0¤cy_code=USD");builder.AppendFormat("&item_name={0}",HttpUtility.UrlEncode(ItemName));builder.AppendFormat("&invoice={0}",TransactionId);builder.AppendFormat("&amount={0}",金额);builder.AppendFormat("&return={0}",HttpUtility.UrlEncode(ReturnUrl));builder.AppendFormat("&cancel_return={0}",HttpUtility.UrlEncode(CancelUrl));builder.AppendFormat("&undefined_quantity={0}",数量);builder.AppendFormat("&item_number={0}",HttpUtility.UrlEncode(ItemNumber));Response.Redirect(builder.ToString());}以下是有关PayPal标准字符段的更多信息–PayPal支付标准的HTML变量您可以使用C#动态创建表单并发布它以下代码做了–protectedvoidPay(){RemotePostmyremotepost=newRemotePost();myremotepost.Url="https://www.paypal.com/cgi-bin/webscr";myremotepost.Add("业务","merchantemail@gmail.com");myremotepost.Add("cmd","_xclick");myremotepost.Add("item_name","HotSauce-12ozBottle");myremotepost.Add("金额","5.95");myremotepost.Add("currency_code","USD");myremotepost.Post();}publicclassRemotePost{privateSystem.Collections.Specialized.NameValueCollectionInputs=newSystem.Collections.Specialized.NameValueCollection();公共字符串Url="";公共字符串方法=“发布”;公共字符串FormName="form1";publicvoidAdd(stringname,stringvalue){Inputs.Add(name,value);}publicvoidPost(){System.Web.HttpContext.Current.Response.Clear();System.Web.HttpContext.Current.Response.Write("");System.Web.HttpContext.Current.Response.Write(string.Format("",FormName));System.Web.HttpContext.Current.Response.Write(string.Format("");System.Web.HttpContext.Current.Response.Write("");System.Web.HttpContext.Current.Response.End();}}全面测试和工作!您可以构建一个长URL并将所有内容作为URL参数放入其中但是,由于您使用的是C#,我建议您使用API。在这种情况下,我会看一下ExpressCheckout。以上是C#学习教程:如何使用c#中的参数将用户重定向到paypal分享的全部内容。如果对你有用,需要进一步了解C#学习教程,希望大家多多关注。本文来自网络收藏,不代表立场,如涉及侵权,请点击右边联系管理员删除。如需转载请注明出处:
