Example #1
0
        /// <summary>
        /// 查询订单
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public Data.OrderResponse OrderQuery(Data.OrderQueryRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException();
            }
            request.sign = Config.Signature(request);
            var xml = Util.XmlSerializer.Serialize(request).InnerXml;

            string content;

            using (var client = new System.Net.Http.HttpClient())
            {
                var response = client.PostAsync(new Uri("https://api.mch.weixin.qq.com/pay/orderquery"), new System.Net.Http.StringContent(xml, Encoding.UTF8)).Result;
                content = response.Content.ReadAsStringAsync().Result;
            }

            var dom = new System.Xml.XmlDocument();

            dom.LoadXml(content);
            var result = Util.XmlSerializer.Deserialize <Data.OrderResponse>(dom);

            if (result.return_code == "FAIL")
            {
                throw new WechatException(result.return_msg);
            }
            return(result);
        }
Example #2
0
        /// <summary>
        /// 查询订单
        /// </summary>
        /// <param name="out_trade_no"></param>
        /// <returns></returns>
        public Data.OrderResponse OrderQuery(string out_trade_no)
        {
            if (string.IsNullOrWhiteSpace(out_trade_no))
            {
                throw new ArgumentNullException();
            }

            var request = new Data.OrderQueryRequest
            {
                appid        = Config.AppId,
                mch_id       = Config.MchId,
                nonce_str    = Guid.NewGuid().ToString("N"),
                out_trade_no = out_trade_no
            };

            return(OrderQuery(request));
        }