我是非常非常新的。Net和需要一些帮助,所以裸请。我试图创建一个后台办公系统与整合与sagepay使用sagepay管理和报告的API。我发现了一个样本代码在线这是非常有益的,但我得到上述错误时,我试图使一个调用的API。这里是一个样本代码下面的调用。我想知道是否有人可以告诉我在哪里我'我错了?
private string BuildCommandString(string command, string vendor, string user, string xmldata, string password = null, string signature = null)
{
return string.Format("<command>{0}</command><vendor>{1}</vendor><user>{2}</user>{3}{4}{5}",
command,
Vendor,
User,
xmldata ?? string.Empty,
(string.IsNullOrEmpty(password) == false ? "<password>" + password + "</password>" : string.Empty),
(string.IsNullOrEmpty(signature) == false ? "<signature>" + signature + "</signature>" : string.Empty));
}
/// <summary>
/// Perform the main call for the API and collect the response
/// </summary>
/// <param name="command">api command name</param>
/// <param name="xmldata">optional extra data for api</param>
/// <returns>new SagePayResponse or null if communication error</returns>
protected SagePayResponse ProcessAPI(string command, string xmldata)
{
// get the requiest
HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(Url);
httpRequest.Method = "POST";
// build data
string data = BuildCommandString(command, Vendor, User, xmldata, Password);
// apply signature
MD5 md5 = new MD5CryptoServiceProvider();
byte[] hash = md5.ComputeHash(Encoding.UTF8.GetBytes(data));
string sig = BitConverter.ToString(hash).Replace("-", string.Empty);
// rebuild with signature
data = "XML=<vspaccess>" + BuildCommandString(command, Vendor, User, xmldata, null, sig) + "</vspaccess>";
// get the data
byte[] bytes = Encoding.UTF8.GetBytes(data);
httpRequest.ContentType = "application/x-www-form-urlencoded";
httpRequest.ContentLength = data.Length;
// get the request stream
Stream requestStream = httpRequest.GetRequestStream();
requestStream.Write(bytes, 0, bytes.Length);
requestStream.Close();
// call the sagepay url and get response
SagePayResponse sagePayResponse = null;
HttpWebResponse response = (HttpWebResponse)httpRequest.GetResponse();
try
{
if (response.StatusCode == HttpStatusCode.OK)
{
Stream responseStream = response.GetResponseStream();
//string contentType = response.ContentType;
StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
try
{
//Console.WriteLine("response ok");
sagePayResponse = new SagePayResponse(reader.ReadToEnd());
}
finally
{
reader.Close();
}
}
}
finally
{
response.Close();
}
return sagePayResponse;
}
2条答案
按热度按时间wa7juj8i1#
@ Mandar Jogalekar我希望这能有所帮助
2izufjch2#
如果其他人正在寻找有关SagePay报告和管理API的帮助,您可以在这里找到NuGet包:
https://www.nuget.org/packages/Joe.Opayo.Admin.Api.Client/1.1.0
客户端应用程序允许如下代码: