我正在尝试在我的网络应用程序中实现 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">
但我收到此错误:
最佳答案
这是我的错误。因为签名不是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/