我有C#asp.net Web窗体项目。我正在使用信用卡付款系统,该系统向我返回3d付款页面的html代码(不自动重定向)。这是我的要求;

                thirdBasketItem.Price = "0.2";
                basketItems.Add(thirdBasketItem);
                request.BasketItems = basketItems;

                ThreedsInitialize threedsInitialize = ThreedsInitialize.Create(request, options);
                var dynamicHtml = threedsInitialize.HtmlContent;


这是我的dynamicHtml变量值;

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
 <head>
  <title>MDpay default response template for web</title>
 </head>
 <body onload="OnLoadEvent();">
  <form name="downloadForm" action="https://acs.bkm.com.tr/mdpayacs/pareq" method="POST">
   <input type="hidden" name="PaReq" value="eJxdUl1P4zAQfOdXRHm/+KNO2yDXiEIRfeAEpXDiMefsUUskKU5ybfn1t07rc0oURd6Z8e5mduXV
vvyI/oJtTF3NYpbQOIJK14Wp3mfxy/ruxzS+UhdyvbEAt8+gOwvqIorkAzRN/g6RKfDWeCwYz0Qa
OwrJx+sVfB7PGJ2yK0yecEl86OkH+iJvQXHKJhQ/EZtephRf
SXp8YFrpulbr1VvEEo78CQiKrevl+ogypxgCAys6a3EHDioTGXrhoyCA/bauAO+gVf/Pg36h0REJ
nny3QN7cn81atzi1MR+NGJ+K1I27R87qGZwGH1PRFzRhNJL4ZFjHb50bQ7+duLjkfHP/AT7Qy6g=" />
   <input type="hidden" name="TermUrl" value="https://sanalpos.teb.com.tr/fim/est3Dgate?msgid=16945" />
   <input type="hidden" name="MD" value="402591:30D0FEDACD3047305C8E24EBC3739AC3E87C8:4273:##400644452" />
   <!-- To support javascript unaware/disabled browsers -->
   <div style="text-align: center;">
    <img src="templates/preloader.gif" />
    <br />
    <noscript>
     <center>
      Please click the submit button below.
      <br />
      <input type="submit" name="submit" value="Submit" />
     </center>
    </noscript>
   </div>
  </form>
  <script language="Javascript">
  function OnLoadEvent() {
    document.downloadForm.submit();
  }
</script>
 </body>
</html>


如何在弹出窗口或其他窗口上显示此内容以显示客户?

最佳答案

我认为更好的解决方案是使用post生成重定向,而我已经使用3D安全付款完成了此操作,并且对我有用

 NameValueCollection data = new NameValueCollection();

data.Add("PaReq", "eJxdUl1P4zAQfOdXRHm/+KNO2yDXiEIRfeAEpXDiMefsUUskKU5ybfn1t07rc0oURd6Z8e5mduXV
vvyI/oJtTF3NYpbQOIJK14Wp3mfxy/ruxzS+UhdyvbEAt8+gOwvqIorkAzRN/g6RKfDWeCwYz0Qa
OwrJx+sVfB7PGJ2yK0yecEl86OkH+iJvQXHKJhQ/EZtephRf
SXp8YFrpulbr1VvEEo78CQiKrevl+ogypxgCAys6a3EHDioTGXrhoyCA/bauAO+gVf/Pg36h0REJ
nny3QN7cn81atzi1MR+NGJ+K1I27R87qGZwGH1PRFzRhNJL4ZFjHb50bQ7+duLjkfHP/AT7Qy6g=");

data.Add("TermUrl", "https://sanalpos.teb.com.tr/fim/est3Dgate?msgid=16945");

data.Add("MD", "402591:30D0FEDACD3047305C8E24EBC3739AC3E87C8:4273:##400644452");
RedirectAndPOST(this.Page, "https://acs.bkm.com.tr/mdpayacs/pareq", data);


    /// <summary>
    /// POST data and Redirect to the specified url using the specified page.
    /// </summary>
    /// <param name="page">The page which will be the referrer page.</param>
    /// <param name="destinationUrl">The destination Url to which
    /// the post and redirection is occuring.</param>
    /// <param name="data">The data should be posted.</param>
    /// <Author>Samer Abu Rabie</Author>

    public static void RedirectAndPOST(Page page, string destinationUrl,
                                       NameValueCollection data)
    {
        //Prepare the Posting form
        string strForm = PreparePOSTForm(destinationUrl, data);
        //Add a literal control the specified page holding
        //the Post Form, this is to submit the Posting form with the request.
        page.Controls.Add(new LiteralControl(strForm));
    }

    /// <summary>
    /// This method prepares an Html form which holds all data
    /// in hidden field in the addetion to form submitting script.
    /// </summary>
    /// <param name="url">The destination Url to which the post and redirection
    /// will occur, the Url can be in the same App or ouside the App.</param>
    /// <param name="data">A collection of data that
    /// will be posted to the destination Url.</param>
    /// <returns>Returns a string representation of the Posting form.</returns>
    /// <Author>Samer Abu Rabie</Author>
    private static String PreparePOSTForm(string url, NameValueCollection data)
    {
        //Set a name for the form
        string formID = "PostForm";
        //Build the form using the specified data to be posted.
        StringBuilder strForm = new StringBuilder();
        strForm.Append("<form id=\"" + formID + "\" name=\"" +
                       formID + "\" action=\"" + url +
                       "\" method=\"POST\">");

        foreach (string key in data)
        {
            strForm.Append("<input type=\"hidden\" name=\"" + key +
                           "\" value=\"" + data[key] + "\">");
        }

        strForm.Append("</form>");
        //Build the JavaScript which will do the Posting operation.
        StringBuilder strScript = new StringBuilder();
        strScript.Append("<script language='javascript'>");
        strScript.Append("var v" + formID + " = document." +
                         formID + ";");
        strScript.Append("v" + formID + ".submit();");
        strScript.Append("</script>");
        //Return the form and the script concatenated.
        //(The order is important, Form then JavaScript)
        return strForm.ToString() + strScript.ToString();
    }


https://www.codeproject.com/Articles/37539/Redirect-and-POST-in-ASP-NET

关于javascript - 将动态HTML内容写入页面或弹出窗口,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41984506/

10-10 03:18