Example #1
0
        private const string Order_QUERY_Url = "https://api.mch.weixin.qq.com/pay/orderquery";//订单查询


        public PaymentProvider(string appID, string mchID,string notifyURL,string key)
        {
            ParamCheckHelper.WhiteSpaceThrow(appID, "appID");
            ParamCheckHelper.WhiteSpaceThrow(mchID, "mchID");
            ParamCheckHelper.WhiteSpaceThrow(notifyURL, "notifyURL");
            ParamCheckHelper.WhiteSpaceThrow(key, "key");
        
            this.AppID = appID;           
            this.MchID = mchID;            
            this.NotifyURL = notifyURL;            
            this.KEY = key;
        }
Example #2
0
        /// <summary>
        /// 订单查询
        /// </summary>
        /// <param name="byTransactionID"></param>
        /// <param name="identify"></param>
        /// <returns></returns>
        private PayQueryResult OrderQuery(bool byTransactionID, string identify)
        {
            ParamCheckHelper.WhiteSpaceThrow(identify, "identify");
            ParamCheckHelper.LimitLengthThrow(identify, 32, "identify");

            string nonce_str = Guid.NewGuid().ToString().Replace("-", "");

            SortedDictionary<string, string> parameters = new SortedDictionary<string, string>();
            StringBuilder builder = new StringBuilder();
            builder.Append("<xml>");
            builder.Append("<appid>" + this.AppID + "</appid>");
            parameters.Add("appid", this.AppID);

            builder.Append("<mch_id>" + this.MchID + "</mch_id>");
            parameters.Add("mch_id", this.MchID);

            if (byTransactionID)
            {
                builder.Append("<transaction_id>" + identify + "</transaction_id>");
                parameters.Add("transaction_id", identify);
            }
            else
            {
                builder.Append("<out_trade_no>" + identify + "</out_trade_no>");
                parameters.Add("out_trade_no", identify);
            }

            builder.Append("<nonce_str>" + nonce_str + "</nonce_str>");
            parameters.Add("nonce_str", nonce_str);

            string sign = CalcSign(parameters);

            builder.Append("<sign>" + sign + "</sign>");
            builder.Append("</xml>");

            string xml = string.Empty;
            try
            {
                xml = ZTImage.HttpEx.SyncPost(Order_QUERY_Url, builder.ToString(), Encoding.UTF8);
            }
            catch (Exception ex)
            {
                ZTImage.Log.Trace.Error("订单查询时出现错误", ex);
            }

            return ParseOrderQuery(xml);
        }