【发布时间】:2016-08-30 13:40:30
【问题描述】:
我正在使用 Realex XML API 使用此处的 GitHub .Net 库向 MPI 服务器发送 3D 安全注册请求: https://github.com/JonCanning/RealEx.NET
身份验证过程的前两个步骤对于 3D 安全测试卡 4012001037141112 运行良好,这应该会导致成功的 3D 安全身份验证,但是在尝试反序列化 .Net 类下的 XML 时,ThreeDSecure 永远不会被填充并且总是尽管相应地填充了 XML,但仍为 null:
<response timestamp="20160830142152">
<merchantid>*****</merchantid>
<account>internet</account>
<orderid>92f669c7-6fb3-43e0-bfb9-8f62aca128cf</orderid>
<authcode />
<result>00</result>
<message>Authentication Successful</message>
<pasref />
<timetaken>0</timetaken>
<authtimetaken>0</authtimetaken>
<threedsecure>
<status>Y</status>
<eci>5</eci>
<cavv>AAACBDlZYkmAggkgJVliAAAAAAA=</cavv>
<xid>ZFD6gQMih8V5gzA3q/XODcrx8N8=</xid>
<algorithm>2</algorithm>
</threedsecure>
<sha1hash>a9800768d3e683de4cf074195884d67d29f79189</sha1hash>
</response>
.Net 类的代码如下:
namespace RealEx
{
[XmlRoot("response")]
public class RealExResponse
{
[XmlElement("result")]
public string Result { get; set; }
[XmlElement("message")]
public string Message { get; set; }
[XmlElement("pasref")]
public string PasRef { get; set; }
[XmlElement("authcode")]
public string AuthCode { get; set; }
[XmlElement("pareq")]
public string PaReq { get; set; }
[XmlElement("enrolled")]
public string Enrolled { get; set; }
[XmlElement("xid")]
public string Xid { get; set; }
[XmlElement("orderid")]
public string OrderId { get; set; }
[XmlElement("sha1hash")]
public string Sha1Hash { get; set; }
[XmlElement("merchantid")]
public string MerchantId { get; set; }
[XmlElement("account")]
public string Account { get; set; }
[XmlElement("timetaken")]
public string TimeTaken { get; set; }
[XmlElement("authtimetaken")]
public string AuthTimeTaken { get; set; }
[XmlElement("url")]
public string Url { get; set; }
[XmlAttribute("timestamp")]
public string TimeStamp { get; set; }
[XmlElement("threedsecure")]
public ThreeDSecure ThreeDSecure { get; set; }
[XmlElement("cvnresult")]
public string CvnResult { get; set; }
[XmlElement("avspostcoderesponse")]
public string AvsPostcodeResponse { get; set; }
[XmlElement("avsaddressresponse")]
public string AvsAddressResponse { get; set; }
[XmlElement("batchid")]
public string BatchId { get; set; }
[XmlElement("cardissuer")]
public CardIssuer CardIssuer { get; set; }
internal static RealExResponse Deserialize(string xml)
{
return new XmlSerializer(typeof(RealExResponse)).Deserialize(XDocument.Parse(xml).CreateReader()) as RealExResponse;
}
}
}
namespace RealEx
{
public class ThreeDSecure
{
public string Status { get; set; }
public string Eci { get; set; }
public string Cavv { get; set; }
public string Xid { get; set; }
public string Algorithm { get; set; }
}
}
namespace RealEx
{
public class RealEx3DAuthRequest : RealExAuthRequest
{
public RealEx3DAuthRequest(string secret, string merchantId, string account, string orderId, Amount amount, Card card, TssInfo tssInfo, ThreeDSecure threeDSecure, bool autoSettle, string custNum, string prodId, string varRef, Comments comments)
: base(secret, merchantId, account, orderId, amount, card, tssInfo, autoSettle, custNum, prodId, varRef, comments)
{
Mpi = new Mpi(threeDSecure.Cavv, threeDSecure.Xid, threeDSecure.Eci);
}
public Mpi Mpi { get; private set; }
}
}
我不明白为什么在正确写入所有其他属性的情况下,响应中收到的信息没有写入类中,谁能帮我理解这个问题?
【问题讨论】:
-
@EdPlunkett 它只是一个带有转义字符的字符串。我已经编辑为正确格式。
-
@EdPlunkett 在这种情况下,声称它没有解析为 XML 有点不诚实。
-
@CharlesMager 我在这里看到了反斜杠原来是字符串中的实际反斜杠的问题。你真的不知道这些人。当你想一想时,我为理解他付出的努力比他为被理解付出的更多。
标签: c# xml serialization deserialization realex-payments-api