c# - 无法处理带有引用代码 [xxx] 的订单,该标志无效 PayU

标签 c# asp.net asp.net-mvc-4 payment-gateway payu

我正在尝试在我的网络应用程序中实现 Pay U 支付网关。

我使用示例表单在 PayU 表单中过帐付款值。

请参阅下面我的代码。

<form method="post" action="https://gateway.payulatam.com/ppp-web-gateway/">
<input name="merchantId" type="hidden" value="XXXXXX">
<input name="accountId" type="hidden" value="XXXXXX">
<input name="description" type="hidden" value="Test PAYU">
<input name="referenceCode" type="hidden" value="payment_test_00000001">
<input name="amount" type="hidden" value="3">
<input name="tax" type="hidden" value="0">
<input name="taxReturnBase" type="hidden" value="0">
<input name="currency" type="hidden" value="USD">
<input name="signature" type="hidden" value="be2f083cb3391c84fdf5fd6176801278">
<input name="test" type="hidden" value="1">
<input name="buyerEmail" type="hidden" value="<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9ae8fbfdffe9f2b4eae8dac2c2c2b4f9f5f7" rel="noreferrer noopener nofollow">[email protected]</a>">
<input name="responseUrl" type="hidden" value="http://www.test.com/response">
<input name="confirmationUrl" type="hidden" value="http://www.test.com/confirmation">
<input name="Submit" type="submit" value="Enviar">

但我收到此错误:

enter image description here

最佳答案

这是我的错误。因为签名不是MD5字符串。

<input name="signature" type="hidden" value="be2f083cb3391c84fdf5fd6176801278">

需要编写一个新函数来创建 MD5 字符串。

    public static string CalculateMD5Hash(string input)
    {
        // step 1, calculate MD5 hash from input
        MD5 md5 = System.Security.Cryptography.MD5.Create();
        byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
        byte[] hash = md5.ComputeHash(inputBytes);

        // step 2, convert byte array to hex string
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < hash.Length; i++)
        {
            sb.Append(hash[i].ToString("x2"));
        }
        return sb.ToString();
    }

然后像下面一样调用这个函数。

        string Signature = CommonHelper.CalculateMD5Hash(ApiKey + "~" + MerchantId + "~" + ReferenceCode + "~" + Amount + "~" + Currency);

(请保持上述函数中的参数顺序。)

现在签名已创建。

在表单中传递此签名。

工作正常。

:)

关于c# - 无法处理带有引用代码 [xxx] 的订单,该标志无效 PayU,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28742439/

相关文章:

jquery - 在mvc 4中将Json数据绑定(bind)到表

asp.net - 如何为 ASP Razor MVC 设置默认布局

jquery - jquery中的MVC字符串编码问题

c# - 参数化 DllImport 以在 C# 应用程序中使用

c# - 从 ASP.Net 迁移到 Java 进行 Web 开发

c# - 如何从字符串中删除字符的确切出现?

asp.net - VS2010 和 CSS : What is the best strategy to individually position form controls

C# 在 WndProc 中检测点击并在点击发生后调用函数

asp.net - GridView 编辑按钮需要单击 2 次

javascript - UpdatePanel 触发时图像不显示