Migs 与 C# 集成,包括带有 SHA256 哈希的卡详细信息
问问题
339 次
1 回答
1
以下是取自proj 解决方案的工作代码
var secureSecret = "123456789ABCDEF123456789ABCDEF12";
var args = new SortedDictionary<string, string>()
{
{"vpc_Version", "1"},
{"vpc_Command", "refund"},
{"vpc_MerchTxnRef", "TestRefund"},
{"vpc_AccessCode", "XXXXXXXX"},
{"vpc_Merchant", "XXXXXXXX"},
{"vpc_TransNo", "123"},
{"vpc_Amount", "1"}
};
var getPart = "";
foreach (var arg in args)
{
getPart += arg.Key + "=" + arg.Value + "&";
}
getPart = getPart.TrimEnd('&');
var keyBytes = new byte[secureSecret.Length / 2];
for(int i=0;i<keyBytes.Length;i++)
{
keyBytes[i] = byte.Parse(secureSecret.Substring(i * 2, 2), System.Globalization.NumberStyles.HexNumber);
}
var hmac = new HMACSHA256(keyBytes);
var hash = hmac.ComputeHash(Encoding.ASCII.GetBytes(getPart));
var hashString = BitConverter.ToString(hash).Replace("-", "");
var requestUri = "https://migs.mastercard.com.au/vpcpay?"+getPart+"&vpc_SecureHash="+hashString+"&vpc_SecureHashType=SHA256";
于 2018-01-22T16:02:26.753 回答