zoukankan      html  css  js  c++  java
  • 阿里大于短信返回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;
            }
    XML返回对象

     返回对象后

     var model = AlidayuFromXml(rsp.Body.ToString());
                if (model.ContainsKey("success"))
                {
                    //编写成功之后要进行的事务
                }else{
    }
    
  • 相关阅读:
    面向对象 小游戏 打飞机
    面向对象2
    面向对象
    正则 校验邮箱
    正则 过滤敏感字
    Strobogrammatic Number
    Binary Tree Right Side View
    [?]*Closest Binary Search Tree Value II
    *Closest Binary Search Tree Value
    *Inorder Successor in BST
  • 原文地址:https://www.cnblogs.com/danlis/p/5719399.html
Copyright © 2011-2022 走看看