Opayo API - 无法验证签名
Opayo API - Unable to validate signature
我一直在尝试连接到 Opayo 'Reporting & Admin API' 并使用命令 'getTransactionDetail' (https://developer-eu.elavon.com/docs/opayo-reporting-api/reporting-commands/gettransactiondetail),但一直返回错误 0010,这表明 API 无法验证签名值。我们已经能够使用我们的 Vendor/Username/Password 组合登录,验证它们都是正确的。
我们在向 API 发送 POST 时使用的代码如下 - 为了安全起见,某些元素被屏蔽了。
using System;
using System.Collections.Specialized;
using System.Security.Cryptography;
using System.Text;
using System.Net;
public partial class test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string signature = "<command>getTransactionDetail</command><vendor>[Vendor]</vendor><user>[User]</user><vendortxcode>[VendorTXCode]</vendortxcode><password>[Password]</password>";
using (MD5 md5 = MD5.Create())
{
byte[] inputBytes = Encoding.Unicode.GetBytes(signature);
byte[] hashBytes = md5.ComputeHash(inputBytes);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hashBytes.Length; i++)
{
sb.Append(hashBytes[i].ToString("X2"));
}
signature = sb.ToString();
}
string xmlToPost = "<vspaccess><command>getTransactionDetail</command><vendor>[Vendor]</vendor><user>[User]</user><vendortxcode>[VendorTXCode]</vendortxcode><signature>" + signature + "</signature></vspaccess>";
using (WebClient client = new WebClient())
{
client.BaseAddress = "https://test.sagepay.com";
client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
client.Encoding = Encoding.UTF8;
var content = new NameValueCollection()
{
{ "XML", xmlToPost }
};
string response = Encoding.UTF8.GetString(client.UploadValues("/access/access.htm", content));
}
}
}
如能帮助解决此问题,我们将不胜感激!
事实证明,由于我们使用 Forms 集成进行初始付款,我们不得不改用以下 API 文档:https://developer-eu.elavon.com/docs/opayo/spec/api-reference
更具体地说,这部分与重复有关:https://developer-eu.elavon.com/docs/opayo/spec/api-reference#operation/createTransaction
注意右侧的代码示例!
我一直在尝试连接到 Opayo 'Reporting & Admin API' 并使用命令 'getTransactionDetail' (https://developer-eu.elavon.com/docs/opayo-reporting-api/reporting-commands/gettransactiondetail),但一直返回错误 0010,这表明 API 无法验证签名值。我们已经能够使用我们的 Vendor/Username/Password 组合登录,验证它们都是正确的。
我们在向 API 发送 POST 时使用的代码如下 - 为了安全起见,某些元素被屏蔽了。
using System;
using System.Collections.Specialized;
using System.Security.Cryptography;
using System.Text;
using System.Net;
public partial class test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string signature = "<command>getTransactionDetail</command><vendor>[Vendor]</vendor><user>[User]</user><vendortxcode>[VendorTXCode]</vendortxcode><password>[Password]</password>";
using (MD5 md5 = MD5.Create())
{
byte[] inputBytes = Encoding.Unicode.GetBytes(signature);
byte[] hashBytes = md5.ComputeHash(inputBytes);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hashBytes.Length; i++)
{
sb.Append(hashBytes[i].ToString("X2"));
}
signature = sb.ToString();
}
string xmlToPost = "<vspaccess><command>getTransactionDetail</command><vendor>[Vendor]</vendor><user>[User]</user><vendortxcode>[VendorTXCode]</vendortxcode><signature>" + signature + "</signature></vspaccess>";
using (WebClient client = new WebClient())
{
client.BaseAddress = "https://test.sagepay.com";
client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
client.Encoding = Encoding.UTF8;
var content = new NameValueCollection()
{
{ "XML", xmlToPost }
};
string response = Encoding.UTF8.GetString(client.UploadValues("/access/access.htm", content));
}
}
}
如能帮助解决此问题,我们将不胜感激!
事实证明,由于我们使用 Forms 集成进行初始付款,我们不得不改用以下 API 文档:https://developer-eu.elavon.com/docs/opayo/spec/api-reference
更具体地说,这部分与重复有关:https://developer-eu.elavon.com/docs/opayo/spec/api-reference#operation/createTransaction
注意右侧的代码示例!