                description = "数据获取异常，请重新审核";

                return -3;
            }

            XmlDocument XmlDoc = new XmlDocument();

            try
            {
                XmlDoc.Load(new StringReader(AlipayResult));
            }
            catch
            {
                description = "数据获取异常，请重新审核";

                return -4;
            }

            System.Xml.XmlNodeList nodesIs_success = XmlDoc.GetElementsByTagName("is_success");

            if ((nodesIs_success == null) || (nodesIs_success.Count < 1))
            {
                description = "查询信息获取异常，请重新查询";

                return -5;
            }

            string is_success = nodesIs_success[0].InnerText;

            if (is_success.ToUpper()!= "T")
            {
                description = "该支付记录未支付成功";

                return -6;
            }

            System.Xml.XmlNodeList nodesTrade_no = XmlDoc.GetElementsByTagName("trade_no");

            if ((nodesTrade_no == null) || (nodesTrade_no.Count < 1))
            {
                description = "没有对应的支付信息";

                return -7;
            }

            alipaypaymentNumber = nodesTrade_no[0].InnerText;

            System.Xml.XmlNodeList nodesTrade_Status = XmlDoc.GetElementsByTagName("trade_status");

            if ((nodesTrade_Status == null) || (nodesTrade_Status.Count < 1))
            {
                description = "没有对应的支付信息";

                return -8;
            }

            string Trade_Status = nodesTrade_Status[0].InnerText.ToUpper();

            if (Trade_Status == "WAIT_BUYER_PAY")
            {
                description = "等待买家付款";

                return -9;
            }

            if (Trade_Status == "WAIT_SELLER_SEND_GOODS")
            {
                description = "买家付款成功(担保交易，未确定支付给商家)";

                return -10;
            }

            if (Trade_Status == "WAIT_BUYER_CONFIRM_GOODS")
            {
                description = "卖家发货成功(未确定支付给商家)";

                return -11;
            }

            if (Trade_Status == "TRADE_CLOSED")
            {
                description = "交易被关闭，未成功付款";

                return -12;
            }

            if (Trade_Status!= "TRADE_FINISHED")
            {
                description = "其他未成功支付的错误";

                return -9999;
            }

            return 0;
        }
        #endregion

        #region     地址构建

        /// <summary>
        /// 支付宝地址构建 （仅适应 MSSQL 数据库）
        /// </summary>
        /// <param name="gateway"></param>
        /// <param name="service"></param>
        /// <param name="partner"></param>
        /// <param name="return_url"></param>
        /// <param name="notify_url"></param>
        /// <param name="out_trade_no"></param>
        /// <param name="subject"></param>
        /// <param name="payment_type"></param>
        /// <param name="total_fee"></param>
        /// <param name="seller_email"></param>
        /// <param name="key"></param>
        /// <param name="charset"></param>
        /// <param name="signType"></param>
        /// <param name="paramsAndValue"></param>
        /// <returns></returns>
        public string CreatUrl(
        string gateway,
        string service,
        string partner,
        string return_url,
        string notify_url,
        string out_trade_no,
        string subject,
        string payment_type,
        string total_fee,
        string seller_email,
        string key,
        string charset,
        string signType,
        params string[] paramsAndValue)
        {
            GetOption();

            return CreateUrl_Public(gateway, service, partner, return_url, notify_url, out_trade_no, subject, payment_type, total_fee, seller_email, key, charset, signType, paramsAndValue);
        }

        /// <summary>
        /// 支付宝地址构建 2010-7-7（如果使用的数据库不是 MSSQL，请使用此方法）
        /// </summary>
        /// <param name="gateway"></param>
        /// <param name="service"></param>
        /// <param name="partner"></param>
        /// <param name="return_url"></param>
        /// <param name="notify_url"></param>
        /// <param name="out_trade_no"></param>
        /// <param name="subject"></param>
        /// <param name="payment_type"></param>
        /// <param name="total_fee"></param>
        /// <param name="seller_email"></param>
        /// <param name="key"></param>
        /// <param name="charset"></param>
        /// <param name="signType"></param>
        /// <param name="type">type 表示数据库类型 1 MSSQL 2 MySQL</param>
        /// <param name="paramsAndValue"></param>
        /// <returns></returns>
        public string CreatUrl(
        string gateway,
        string service,
        string partner,
        string return_url,
        string notify_url,
        string out_trade_no,
        string subject,
        string payment_type,
        string total_fee,
        string seller_email,
        string key,
        string charset,
        string signType,
        int type,
        params string[] paramsAndValue)
        {
            if (type == 2)
            {
                GetOptionForMySQL();
            }
            else
            {
                GetOption();
            }

            return CreateUrl_Public(gateway, service, partner, return_url, notify_url, out_trade_no, subject, payment_type, total_fee, seller_email, key, charset, signType, paramsAndValue);

        }

        private string CreateUrl_Public(
        string gateway,
        string service,
        string partner,
        string return_url,
        string notify_url,
        string out_trade_no,
        string subject,
        string payment_type,
        string total_fee,
        string seller_email,
        string key,
        string charset,
        string signType,
        params string[] paramsAndValue)
        {
            string Royalty = "10";
            string ServicesUser = "";

            double _FormalitiesFees = 0.01;

            partner = PartnerID;
            key = PartnerKey;
            ServicesUser = ServicesAccount;
            _FormalitiesFees = FormalitiesFees;

            if (!gateway.EndsWith("?", StringComparison.Ordinal))
            {
                gateway += "?";
            }

            ArrayList al = new ArrayList();

            ////////////////////////////计算服务费/////////////////////////////////////
            double Tmptotal_fee = 0;

            try
            {
                Tmptotal_fee = System.Convert.ToDouble(total_fee);
            }
            catch
            {
                return "";
            }

            _FormalitiesFees = Math.Round(Tmptotal_fee * _FormalitiesFees, 2);

            string RoyaltyPparameters = "";
            if (_FormalitiesFees > 0)
            {
                RoyaltyPparameters = ServicesUser + "^" + _FormalitiesFees.ToString() + "^alipay_service";
            }
            //////////////////////////计算服务费结束///////////////////////////////////

            al.Add("seller_email=" + seller_email);
            al.Add("subject=" + subject);
            al.Add("out_trade_no=" + out_trade_no);
            al.Add("total_fee=" + total_fee);
            al.Add("return_