1

我正在尝试在我的 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="ragesh.pr@XXX.com">
<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">

但我收到此错误:

在此处输入图像描述

4

3 回答 3

1

在您的 C# 控制器方法中包括对 System.Web.Security 的引用。

要构建您的签名,您需要一个字符串,例如为您的国家/地区指示 Payu。在我的情况下,字符串看起来像:

apiKey~merchantId~referenceCode~totalAmount~currency

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

将计算值放入您的表格中。

伟大的。

于 2016-09-15T19:34:40.583 回答
0

It's my mistake. Because the signature is not a MD5 string.

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

it's need to write a new function for 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();
    }

then call this function like below.

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

(Please keep the parameter order in above function.)

Now the signature is created.

pass this signature in the form.

Works fine.

:)

y

于 2015-04-08T03:18:05.330 回答
0

就我而言,我忘记了 algorithmSignature 参数,因为我使用 SHA256 进行签名,默认算法是 MD5

于 2020-12-04T14:07:32.543 回答