无法处理带参考代码[xxx]的订单,该签名无效PayU

问题描述 投票:1回答:2

我正在尝试在我的Web应用程序中实现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="[email protected]">
<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">

但我得到这个错误:

c# asp.net asp.net-mvc-4 payment-gateway payu
2个回答
1
投票

在您的C#controller方法中包含对System.Web.Security的引用。

要建立您的签名,您需要一个字符串,表示您所在国家/地区的Payu。在我的情况下,字符串看起来像:

apiKey〜MERCHANTID〜referenceCode〜总金额〜货币

//build the string for signature in md5 encription
var signatureSource = string.Format("{0}~{1}~{2}~{3}~{4}", apiKey, merchantId, referenceCode, totalAmount, currency);
//get the md5 signature
var signature = FormsAuthentication.HashPasswordForStoringInConfigFile(signatureSource,"md5");

将计算出的值放入表单中。

Greatings。


0
投票

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

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

需要为create MD5 string编写一个新函数。

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

(请将参数顺序保存在上面的功能中。)

现在签名已创建。

在表格中传递此签名。

工作良好。

:)

© www.soinside.com 2019 - 2024. All rights reserved.