我正在为发布请求处理正文有效负载摘要。
我正在使用提供的测试用例来尝试获得与 CyberSource 使用其测试值和测试方法相同的输出 base64。
public static string GenerateDigest() {
var digest = "";
var bodyText = "{ your JSON payload }";
using (var sha256hash = SHA256.Create()) {
byte[] payloadBytes = sha256hash
.ComputeHash(Encoding.UTF8.GetBytes(bodyText));
digest = Convert.ToBase64String(payloadBytes);
digest = "SHA-256=" + digest;
}
return digest;
}
{
"clientReferenceInformation": {
"code": "TC50171_3"
},
"processingInformation": {
"commerceIndicator": "internet"
},
"paymentInformation": {
"card": {
"number": "4111111111111111",
"expirationMonth": "12",
"expirationYear": "2031",
"securityCode": "123"
}
},
"orderInformation": {
"amountDetails": {
"totalAmount": "102.21",
"currency": "USD"
},
"billTo": {
"firstName": "John",
"lastName": "Doe",
"company": "Visa",
"address1": "1 Market St",
"address2": "Address 2",
"locality": "san francisco",
"administrativeArea": "CA",
"postalCode": "94105",
"country": "US",
"email": "test@cybs.com",
"phoneNumber": "4158880000"
}
}
}
我尝试生成 base64 字符串的测试有效负载如下:
var bodyText = @"
{
""clientReferenceInformation"": {
""code"": ""TC50171_3""
},
""processingInformation"": {
""commerceIndicator"": ""internet""
},
""paymentInformation"": {
""card"": {
""number"": ""4111111111111111"",
""expirationMonth"": ""12"",
""expirationYear"": ""2031"",
""securityCode"": ""123""
}
},
""orderInformation"": {
""amountDetails"": {
""totalAmount"": ""102.21"",
""currency"": ""USD""
},
""billTo"": {
""firstName"": ""John"",
""lastName"": ""Doe"",
""company"": ""Visa"",
""address1"": ""1 Market St"",
""address2"": ""Address 2"",
""locality"": ""san francisco"",
""administrativeArea"": ""CA"",
""postalCode"": ""94105"",
""country"": ""US"",
""email"": ""test@cybs.com"",
""phoneNumber"": ""4158880000""
}
}
}
";
和..
var bodyjson = new
{
clientReferenceInformation =
new { code = "TC50171_3" },
processingInformation =
new {
commerceIndicator = "internet"},
paymentInformation =
new { card =
new {
number = "4111111111111111",
expirationMonth = "12",
expirationYear = "2031",
securityCode = "123"
}
},
orderInformation = new
{
amountDetails = new
{
totalAmount = "102.21",
currency = "USD"
},
billTo = new
{
firstName = "John",
lastName = "Doe",
company = "Visa",
address1 = "1 Market St",
address2 = "Address 2",
locality = "san francisco",
administrativeArea = "CA",
postalCode = "94105",
country = "US",
email = "test@cybs.com",
phoneNumber = "4158880000"
}
}
};
var bodystring = JsonConvert.SerializeObject(bodyjson, Formatting.Indented);
返回的 Sha256 byte64 应该是:
SHA-256=a/goIo1XUCr80rnKFCWp7yRpwVL50E9RaunuEHh11XM=
上面的测试用例代码全部来自 Cybersource 入门指南。但是我的身体字符串不会产生相同的结果。
任何援助将不胜感激。