我已经编写了下面的代码,但我得到了未经授权的访问异常,尽管我使用了正确的 API 密钥和 PIN。除了 401 错误代码,我没有收到任何详细的异常。
try
{
string baseUrl = "https://sandbox.usaepay.com/api/v2/";
string sourceKey = "_4ShK4j3D100uXJb07aEw1krwO80VYpM";
string pin = "123456";
string seed = Guid.NewGuid().ToString();
string key = string.Concat(sourceKey, seed, pin);
var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(key);
string authenticationKeySystem.Convert.ToBase64String(plainTextBytes);
Epay usaepay = new Epay();
usaepay.command = "sale";
usaepay.amount = 200;
usaepay.creditcard.number = "4000700011112221";
usaepay.creditcard.expiration = "0921";
usaepay.creditcard.cvc = 999;
usaepay.lineitems = new List<Epay.Lineitems>
{
new Lineitems
{ name = "Test40",
cost = 40,
qty = 2
},
new Lineitems
{ name = "Test60",
cost = 60,
qty = 2
}
};
string serializeData = JsonConvert.SerializeObject(usaepay);
WebClient client = new WebClient();
client.BaseAddress = baseUrl;
client.Headers.Add(HttpRequestHeader.ContentType, "application/json");
client.Headers.Add(HttpRequestHeader.Authorization, "Basic " + authenticationKey);
ServicePointManager.SecurityProtocol = (SecurityProtocolType)768 | (SecurityProtocolType)3072;
var response = client.UploadString("transactions", serializeData);
var result = JsonConvert.DeserializeObject(response);
}
catch(Exception ex)
{
}
请在上面提出建议