PayU Money Service 的支付网关集成在 ASP.NET 中

问题描述 投票:0回答:0

无法重定向到支付网关,因为从 PayU Money 服务接收到哈希参数计算不正确的错误消息。

声明:

Label9 是交易 ID
标签4是金额
Label1 是名字
Label8 是电子邮件
Label10是电话

命名空间:

using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Security.Cryptography;

页面加载代码:

protected void Page_Load(object sender, EventArgs e)
{
    Cmd.Connection = Cn;
    Random random = new Random();
    txnid.Value = (Convert.ToString(random.Next(10000, 20000)));
    txnid.Value = "Hariti" + txnid.Value.ToString();
    Response.Write(txnid.Value.ToString());
    Label9.Text = txnid.Value.ToString();
}

立即付款按钮代码:

protected void Button1_Click(object sender, EventArgs e)
{
    Double amount = Convert.ToDouble(Label4.Text);

    String text = key.Value.ToString() + "|" + txnid.Value.ToString() + "|" + Label4.Text + "|" + "Women Tops" + "|" + Label1.Text + "|" + Label8.Text + "|" + "1" + "|" + "1" + "|" + "1" + "|" + "1" + "|" + "1" + "||||||" + salt.Value.ToString();
    // Response.Write(text);

    byte[] message = Encoding.UTF8.GetBytes(text);

    UnicodeEncoding UE = new UnicodeEncoding();
    byte[] hashValue;
    SHA512Managed hashString = new SHA512Managed();
    string hex = "";
    hashValue = hashString.ComputeHash(message);

    foreach (byte x in hashValue)
    {
        hex += String.Format("{0:x2}", x);
    }

    hash.Value = hex;

    System.Collections.Hashtable data = new System.Collections.Hashtable(); // adding values in gash table for data post
    data.Add("hash", hex.ToString());
    data.Add("key", key.Value);
    data.Add("txnid", txnid.Value);
    // string AmountForm = ;// eliminating trailing zeros

    data.Add("amount", amount);
    data.Add("productinfo", "Women Tops");
    data.Add("firstname", Label1.Text.Trim());
    data.Add("email", Label8.Text.Trim());
    data.Add("phone", Label10.Text.Trim());
    data.Add("udf1", "1");
    data.Add("udf2", "1");
    data.Add("udf3", "1");
    data.Add("udf4", "1");
    data.Add("udf5", "1");

    data.Add("surl", "http://localhost:44376/SuccessPayment.aspx");
    data.Add("furl", "http://localhost:44376/FailurPayment.aspx");

    data.Add("service_provider", "");

    string strForm = PreparePOSTForm("https://test.payu.in/_payment", data);
    Page.Controls.Add(new LiteralControl(strForm));
}

PayU Money提供的方法:

private string PreparePOSTForm(string url, System.Collections.Hashtable data)      // post form
{
    // 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 (System.Collections.DictionaryEntry key in data)
    {
        strForm.Append("<input type=\"hidden\" name=\"" + key.Key +
                       "\" value=\"" + key.Value + "\">");
    }

    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();
}

我尝试对哈希进行一些更改,但仍然遇到相同的错误。

错误信息:

如果您能帮助我获得正确的哈希计算代码,我将非常感谢您。

c# asp.net .net payment-gateway
© www.soinside.com 2019 - 2024. All rights reserved.