示例#1
0
        /// <summary>
        /// 微信订单查询接口XML参数整理
        /// </summary>
        /// <param name="queryorder">微信订单查询参数实例</param>
        /// <param name="key">密钥</param>
        /// <returns></returns>
        protected string getQueryOrderXml(QueryOrder queryorder, string key)
        {
            string return_string = string.Empty;
            SortedDictionary <string, string> sParams = new SortedDictionary <string, string>();

            sParams.Add("appid", queryorder.appid);
            sParams.Add("mch_id", queryorder.mch_id);
            sParams.Add("transaction_id", queryorder.transaction_id);
            sParams.Add("out_trade_no", queryorder.out_trade_no);
            sParams.Add("nonce_str", queryorder.nonce_str);
            queryorder.sign = getsign(sParams, key);
            sParams.Add("sign", queryorder.sign);

            //拼接成XML请求数据
            StringBuilder sbPay = new StringBuilder();

            foreach (KeyValuePair <string, string> k in sParams)
            {
                if (k.Key == "attach" || k.Key == "body" || k.Key == "sign")
                {
                    sbPay.Append("<" + k.Key + "><![CDATA[" + k.Value + "]]></" + k.Key + ">");
                }
                else
                {
                    sbPay.Append("<" + k.Key + ">" + k.Value + "</" + k.Key + ">");
                }
            }
            return_string = string.Format("<xml>{0}</xml>", sbPay.ToString().TrimEnd(','));
            return(return_string);
        }
示例#2
0
        /// <summary>
        /// 获取微信订单明细
        /// </summary>
        public OrderDetail getOrderDetail(QueryOrder queryorder, string key)
        {
            string      post_data    = getQueryOrderXml(queryorder, key);
            string      request_data = PostXmlToUrl(OrderQueryUrl, post_data);
            OrderDetail orderdetail  = new OrderDetail();
            SortedDictionary <string, string> requestXML = GetInfoFromXml(request_data);

            foreach (KeyValuePair <string, string> k in requestXML)
            {
                switch (k.Key)
                {
                case "retuen_code":
                    orderdetail.result_code = k.Value;
                    break;

                case "return_msg":
                    orderdetail.return_msg = k.Value;
                    break;

                case "appid":
                    orderdetail.appid = k.Value;
                    break;

                case "mch_id":
                    orderdetail.mch_id = k.Value;
                    break;

                case "nonce_str":
                    orderdetail.nonce_str = k.Value;
                    break;

                case "sign":
                    orderdetail.sign = k.Value;
                    break;

                case "result_code":
                    orderdetail.result_code = k.Value;
                    break;

                case "err_code":
                    orderdetail.err_code = k.Value;
                    break;

                case "err_code_des":
                    orderdetail.err_code_des = k.Value;
                    break;

                case "trade_state":
                    orderdetail.trade_state = k.Value;
                    break;

                case "device_info":
                    orderdetail.device_info = k.Value;
                    break;

                case "openid":
                    orderdetail.openid = k.Value;
                    break;

                case "is_subscribe":
                    orderdetail.is_subscribe = k.Value;
                    break;

                case "trade_type":
                    orderdetail.trade_type = k.Value;
                    break;

                case "bank_type":
                    orderdetail.bank_type = k.Value;
                    break;

                case "total_fee":
                    orderdetail.total_fee = k.Value;
                    break;

                case "coupon_fee":
                    orderdetail.coupon_fee = k.Value;
                    break;

                case "fee_type":
                    orderdetail.fee_type = k.Value;
                    break;

                case "transaction_id":
                    orderdetail.transaction_id = k.Value;
                    break;

                case "out_trade_no":
                    orderdetail.out_trade_no = k.Value;
                    break;

                case "attach":
                    orderdetail.attach = k.Value;
                    break;

                case "time_end":
                    orderdetail.time_end = k.Value;
                    break;

                default:
                    break;
                }
            }
            return(orderdetail);
        }