阿里大于短信返回XML
返回异常和成功的两种不同,XML返回直接拿alibaba_aliqin_fc_sms_num_send_response判断节点是否有这个名字
官方API地址:
https://api.alidayu.com/doc2/apiDetail?spm=a3142.7629140.1999205496.19.fs37Yu&apiId=25450
<?xml version="1.0" encoding="utf-8" ?> <alibaba_aliqin_fc_sms_num_send_response> <result> <err_code>0</err_code> <model>102330458199^1102997158000</model> <success>true</success> </result> <request_id>z28wpa7p4jz3</request_id> </alibaba_aliqin_fc_sms_num_send_response> <!--top010178001118.n.et2-->
<?xml version="1.0" encoding="utf-8" ?> <error_response> <code>50</code> <msg>Remote service error</msg> <sub_code>isv.invalid-parameter</sub_code> <sub_msg>非法参数</sub_msg> </error_response>
public static SortedDictionary<string, object> AlidayuFromXml(string xml) { SortedDictionary<string, object> obj = new SortedDictionary<string, object>(); if (!string.IsNullOrEmpty(xml)) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xml); //如果传入的节点个数要比index大才行,要不然就表示节点不存在 if (xmlDoc.ChildNodes.Count > 1) { XmlNode xmlNode = xmlDoc.ChildNodes[1];//获取到根节点<xml> XmlElement xeinit = (XmlElement)xmlNode; if (xmlNode.ChildNodes.Count == 2 || xeinit.Name == "alibaba_aliqin_fc_sms_num_send_response") { XmlNode xmlNodeNext = xmlNode.ChildNodes[0]; XmlNodeList nodes = xmlNodeNext.ChildNodes; foreach (XmlNode xn in nodes) { XmlElement xe = (XmlElement)xn; obj[xe.Name] = xe.InnerText;//获取xml的键值对到WxPayData内部的数据中 } } else { XmlNodeList nodes = xmlNode.ChildNodes; foreach (XmlNode xn in nodes) { XmlElement xe = (XmlElement)xn; obj[xe.Name] = xe.InnerText;//获取xml的键值对到WxPayData内部的数据中 } } } } return obj; }
返回对象后
var model = AlidayuFromXml(rsp.Body.ToString()); if (model.ContainsKey("success")) { //编写成功之后要进行的事务 }else{ }
fighting