与C#集成,包括使用SHA256哈希的卡详细信息
答案 0 :(得分:1)
以下是取自proj solution
的工作代码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";