//查询订单
        private bool QueryOrder(string transaction_id, WxPayConfig config)
        {
            WxPayData req = new WxPayData();

            req.SetValue("transaction_id", transaction_id);
            WxPayData res = WxPayApi.OrderQuery(req, config);

            if (res.GetValue("return_code").ToString() == "SUCCESS" &&
                res.GetValue("result_code").ToString() == "SUCCESS")
            {
                //支付成功
                if (res.GetValue("trade_state").ToString() == "SUCCESS")
                {
                    return(true);
                }
                //支付失败
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
        /// <summary>
        /// 检查支付状态
        /// </summary>
        public override void CheckPayState(PayParameter parameter)
        {
            try
            {
                WxPayConfig config          = new WxPayAPI.WxPayConfig(PayFactory.GetInterfaceXmlConfig(PayInterfaceType.WeiXinScanQRCode, parameter.TradeID));
                WxPayData   queryOrderInput = new WxPayData();
                queryOrderInput.SetValue("out_trade_no", parameter.TradeID);
                WxPayData result = WxPayApi.OrderQuery(queryOrderInput, config);
                string    xml    = result.ToXml();
                PayFactory.OnLog(parameter.TradeID, xml);

                if (result.GetValue("return_code").ToString() == "SUCCESS" &&
                    result.GetValue("result_code").ToString() == "SUCCESS")
                {
                    //支付成功
                    if (result.GetValue("trade_state").ToString() == "SUCCESS")
                    {
                        //触发回调函数
                        PayFactory.OnPaySuccessed(parameter.TradeID, xml);
                        return;
                    }
                    else if (result.GetValue("trade_state").ToString() == "NOTPAY")
                    {
                        //这是一开始生成二维码后,会是这个状态
                        return;
                    }
                }
            }
            catch
            {
            }
        }
Exemple #3
0
        public static WxPayData Query(string out_trade_no, PayConfig config, out int succCode)
        {
            WxPayData wxPayData = new WxPayData();

            wxPayData.SetValue("out_trade_no", out_trade_no);
            WxPayData wxPayData2 = WxPayApi.OrderQuery(wxPayData, config, 6);

            if (wxPayData2.GetValue("return_code").ToString() == "SUCCESS" && wxPayData2.GetValue("result_code").ToString() == "SUCCESS")
            {
                if (wxPayData2.GetValue("trade_state").ToString() == "SUCCESS")
                {
                    succCode = 1;
                    return(wxPayData2);
                }
                if (wxPayData2.GetValue("trade_state").ToString() == "USERPAYING")
                {
                    succCode = 2;
                    return(wxPayData2);
                }
            }
            if (wxPayData2.GetValue("err_code").ToString() == "ORDERNOTEXIST")
            {
                succCode = 0;
            }
            else
            {
                succCode = 2;
            }
            return(wxPayData2);
        }
Exemple #4
0
        private void ThreadMethod()
        {
            while (!isNotPay)
            {
                queryOrderInput.SetValue("out_trade_no", out_trade_no1);
                result = WxPayApi.OrderQuery(queryOrderInput);

                Thread.Sleep(1000);
                if (result.GetValue("return_code").ToString() == "SUCCESS" && result.GetValue("result_code").ToString() == "SUCCESS")
                {
                    //支付成功
                    //------------暂时未写付款后的操作-------------------
                    if (result.GetValue("trade_state").ToString() == "SUCCESS")
                    {
                        isNotPay = true;
                        if (printFile(FilePath))
                        {
                            MessageBox.Show("打印成功!");
                        }
                        else
                        {
                            MessageBox.Show("打印失败!");
                        }
                    }
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// 校验支付结果请求
        /// </summary>
        /// <param name="data">业务数据报文</param>
        /// <param name="resultInfo">支付结果记录</param>
        /// <returns></returns>
        public override ExecuteResult CheckRequest(string data, PayResultInfo resultInfo)
        {
            var result    = new ExecuteResult();
            var errorData = new WxPayData();

            try
            {
                //校验请求报文
                var notifyData = new ParameterData();
                notifyData.FromXml(data);

                //检查支付结果中transaction_id是否存在
                resultInfo.OrderId = notifyData.GetValue("out_trade_no") as string;
                resultInfo.TradeNo = notifyData.GetValue("transaction_id") as string;
                if (string.IsNullOrEmpty(resultInfo.TradeNo))
                {
                    resultInfo.ExecuteResult = (int)ResultStatus.Failure;
                    resultInfo.ResultDesc    = "支付结果中微信支付单号不存在";
                    PayResultDAL.Update(resultInfo);

                    errorData.SetValue("return_code", "FAIL");
                    errorData.SetValue("return_msg", resultInfo.ResultDesc);
                    result.Message = errorData.ToXml();
                    result.Status  = ResultStatus.Failure;
                    return(result);
                }

                //查询支付单,判断支付单真实性
                var req = new WxPayData();
                req.SetValue("transaction_id", resultInfo.TradeNo);
                var queryData = WxPayApi.OrderQuery(req);
                if (queryData.GetValue("return_code").ToString() != "SUCCESS" || queryData.GetValue("result_code").ToString() != "SUCCESS")
                {
                    resultInfo.ExecuteResult = (int)ResultStatus.Failure;
                    resultInfo.ResultDesc    = "微信支付单查询失败";
                    PayResultDAL.Update(resultInfo);

                    errorData.SetValue("return_code", "FAIL");
                    errorData.SetValue("return_msg", resultInfo.ResultDesc);
                    result.Message = errorData.ToXml();
                    result.Status  = ResultStatus.Failure;
                    return(result);
                }
            }
            catch (WxPayException wex)
            {
                resultInfo.ExecuteResult = (int)ResultStatus.Error;
                resultInfo.ResultDesc    = wex.Message;
                PayResultDAL.Update(resultInfo);

                errorData.SetValue("return_code", "FAIL");
                errorData.SetValue("return_msg", resultInfo.ResultDesc);
                result.Message = errorData.ToXml();
                result.Status  = ResultStatus.Error;
                return(result);
            }
            result.Status = ResultStatus.Success;
            return(result);
        }
Exemple #6
0
        private WxPayData QueryOrderData(string out_trade_no, string AdminHotelid, int Hotelid)
        {
            WxPayData req = new WxPayData();

            req.SetValue("out_trade_no", out_trade_no);
            WxPayData res = WxPayApi.OrderQuery(req, AdminHotelid, Hotelid);

            return(res);
        }
Exemple #7
0
        private bool QueryOrder(string transaction_id)
        {
            WxPayData req = new WxPayData();

            req.SetValue("transaction_id", transaction_id);
            WxPayData res = WxPayApi.OrderQuery(req, 6);

            return(res.GetValue("return_code").ToString() == "SUCCESS" && res.GetValue("result_code").ToString() == "SUCCESS");
        }
Exemple #8
0
        //查询订单
        private static async Task <bool> QueryOrder(string transactionId)
        {
            var req = new WxPayData();

            req.SetValue("transaction_id", transactionId);
            var res = await WxPayApi.OrderQuery(req);

            return(res.GetValue("return_code").ToString() == "SUCCESS" && res.GetValue("result_code").ToString() == "SUCCESS");
        }
Exemple #9
0
        //获取微信支付结果
        public static string GetWxPayOrderQuery(SOInfo SOInfo, out string Message)
        {
            var data = new WxPayData();

            if (string.IsNullOrEmpty(SOInfo.SOPayInfo.TransactionID))
            {
                data.SetValue("out_trade_no", SOInfo.SalesOrder.BillNO);
            }
            else
            {
                data.SetValue("transaction_id", SOInfo.SOPayInfo.TransactionID);
            }
            var result = WxPayApi.OrderQuery(data);

            //通信标识
            if (result.GetValue("return_code") == null)
            {
                Message = "微信查询订单接口返回空值"; return(null);
            }
            if (result.GetValue("return_code").ToString() != "SUCCESS")
            {
                Message = result.GetValue("return_msg").ToString(); return(null);
            }

            //业务结果
            var result_code = result.GetValue("result_code").ToString();

            if (result_code != "SUCCESS")
            {
                Message = null;
                return(result_code);
            }

            //交易状态
            var trade_state = WxTradeState.FirstOrDefault(i => i.Name == result.GetValue("trade_state").ToString());

            using (var EF = new EF())
            {
                var order_exist = EF.SalesOrders.FirstOrDefault(i => i.ID == SOInfo.SalesOrder.ID);
                if (order_exist == null)
                {
                    Message = "订单编号" + SOInfo.SalesOrder.ID + "不存在"; return(null);
                }
                var pay_exist = EF.SOPayInfos.FirstOrDefault(i => i.SOID == order_exist.ID);
                pay_exist.StateID = trade_state.ID;
                if (trade_state.Name == "SUCCESS")
                {
                    order_exist.StateID     = OMS.SalesOrder.State.FirstOrDefault(i => i.Name == "Paid").ID;
                    pay_exist.TransactionID = result.GetValue("transaction_id").ToString();
                }
                EF.SaveChanges();
            }

            Message = null;
            return(trade_state.Name);
        }
Exemple #10
0
        //查询微信支付订单状态
        public JsonResult CheckTransactionidPayState(string out_trade_no)
        {
            WxPayData data = new WxPayData();

            data.SetValue("appid", PaymentConfigHelper.WxAppId);
            data.SetValue("mch_id", PaymentConfigHelper.WxMCHID);//商户号
            data.SetValue("nonce_str", Guid.NewGuid().ToString().Replace("-", ""));
            data.SetValue("transaction_id", "");
            data.SetValue("out_trade_no", out_trade_no);
            WxPayData result = WxPayApi.OrderQuery(data);

            return(Json(new OperationResult(OperationResultType.Success, "获取成功!", result), JsonRequestBehavior.AllowGet));
        }
        private bool QueryOrder(string transaction_id)
        {
            WxPayData wxPayData = new WxPayData();

            wxPayData.SetValue("transaction_id", transaction_id);
            WxPayData wxPayData2 = WxPayApi.OrderQuery(wxPayData, this.config, 6);

            if (wxPayData2.GetValue("return_code").ToString() == "SUCCESS" && wxPayData2.GetValue("result_code").ToString() == "SUCCESS")
            {
                return(true);
            }
            return(false);
        }
Exemple #12
0
        /// <summary>
        ///     微信回调界面
        /// </summary>
        /// <returns></returns>
        public ViewResultBase WeiXinPayReturn()
        {
            var res        = new WxPayData();
            var notifyData = GetNotifyData();

            //检查支付结果中transaction_id是否存在
            if (!notifyData.IsSet("transaction_id"))
            {
                //若transaction_id不存在,则立即返回结果给微信支付后台
                res.SetValue("return_code", "FAIL");
                res.SetValue("return_msg", "支付结果中微信订单号不存在");
                Log.Error("代码位置:" + GetType() + ".ResultNotifyPage", "--错误详细信息 " + res.ToXml(), "微信");
            }

            var transactionId = notifyData.GetValue("transaction_id").ToString();

            //查询订单,判断订单真实性
            //if (!QueryOrder(transactionId))
            //{
            //    // Log.Info(this.GetType().ToString(), "查询订单失败");
            //    //若订单查询失败,则立即返回结果给微信支付后台
            //    WxPayData res = new WxPayData();
            //    string outTradeNo = res.GetValue("out_trade_no").ToString();
            //    res.SetValue("return_code", "FAIL");
            //    res.SetValue("return_msg", "订单查询失败");
            //    Log.Error("代码位置:" + this.GetType() + ".ResultNotifyPage", "--支付失败,商户订单号 " + outTradeNo, "微信");

            //}
            ////查询订单成功
            //else
            //{
            var req = new WxPayData();

            req.SetValue("transaction_id", transactionId);
            res = WxPayApi.OrderQuery(req);
            var outTradeNo = res.GetValue("out_trade_no").ToString();
            var totalFee   = res.GetValue("total_fee").ToString();

            //更新订单信息
            //var order = await _orderLogic.GetOrderByCode(new IdInput<string>() { Id = outTradeNo });
            //await _orderLogic.PaymentSuccessful(new PayTypeOutpu { Id = order.OrderId, Paytype = 1 });
            res.SetValue("return_code", "SUCCESS");
            res.SetValue("return_msg", "OK");
            Log.Info("代码位置:" + GetType() + ".ResultNotifyPage",
                     "--支付成功,商户订单号:" + outTradeNo + "--支付金额:" + totalFee + "微信支付订单号:" + transactionId, "微信");
            //}
            return(View());
        }
Exemple #13
0
        public static string SendRequest(string transaction_id, string out_trade_no, PayConfig config)
        {
            WxPayData wxPayData = new WxPayData();

            if (!string.IsNullOrEmpty(transaction_id))
            {
                wxPayData.SetValue("transaction_id", transaction_id);
            }
            else
            {
                wxPayData.SetValue("out_trade_no", out_trade_no);
            }
            WxPayData wxPayData2 = WxPayApi.OrderQuery(wxPayData, config, 6);

            return(wxPayData2.ToPrintStr());
        }
        /// <summary>
        /// 查询订单
        /// </summary>
        /// <param name="transactionId"></param>
        /// <returns></returns>
        private bool QueryOrder(string transactionId)
        {
            WxPayData req = new WxPayData();

            req.SetValue("transaction_id", transactionId);
            WxPayData res = WxPayApi.OrderQuery(req);

            if (res.GetValue("return_code").ToString() == "SUCCESS" && res.GetValue("result_code").ToString() == "SUCCESS")
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #15
0
        public PaymentStatusResponse checkStatus(PaymentRequest request)
        {
            PaymentStatusResponse result = new PaymentStatusResponse();

            if (request == null || request.Id == default(Guid) || this.Setting == null)
            {
                return(result);
            }

            try
            {
                var data = new WxPayData();
                data.SetValue("out_trade_no", request.Id.ToString("N"));
                var response = WxPayApi.OrderQuery(data, this.Setting);

                var trade_state = response.GetValue("trade_state");
                //trade_state:SUCCESS,REFUND,NOTPAY,CLOSED,REVOKED,USERPAYING,PAYERROR

                if (trade_state != null)
                {
                    result.HasResult = true;
                    var code = trade_state.ToString().ToUpper();
                    if (code == "SUCCESS")
                    {
                        result.Status = PaymentStatus.Paid;
                    }
                    else if (code == "REFUND" || code == "NOTPAY")
                    {
                        result.Status = PaymentStatus.Cancelled;
                    }
                    else if (code == "CLOSE" || code == "REVOKED" || code == "PAYERROR")
                    {
                        result.Status = PaymentStatus.Cancelled;
                    }
                    else if (code == "USERPAYING")
                    {
                        result.Status = PaymentStatus.Pending;
                    }
                }
            }
            catch (Exception ex)
            {
                Kooboo.Data.Log.Instance.Exception.WriteException(ex);
            }

            return(result);
        }
Exemple #16
0
        //查询订单
        private bool QueryOrder(string transaction_id)
        {
            WxPayData req = GetWxDataMod();

            req.SetValue("out_trade_no", transaction_id);
            WxPayData res = WxPayApi.OrderQuery(req, WxPayApi.Pay_GetByID());

            if (res.GetValue("return_code").ToString() == "SUCCESS" &&
                res.GetValue("result_code").ToString() == "SUCCESS")
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #17
0
        /// <summary>
        /// 查询订单
        /// </summary>
        /// <param name="wxPayConfig"></param>
        /// <param name="transaction_id"></param>
        /// <returns></returns>
        public static bool QueryOrder(WxPayConfig wxPayConfig, string transaction_id)
        {
            WxPayData req = new WxPayData();

            req.SetValue("transaction_id", transaction_id);
            WxPayData res = WxPayApi.OrderQuery(wxPayConfig, req);

            if (res.GetValue("return_code").ToString() == "SUCCESS" &&
                res.GetValue("result_code").ToString() == "SUCCESS")
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #18
0
        public static string GetWxPayBackData(string out_trade_no, string cardId, string orderNo)
        {
            WxPayData data = new WxPayData();

            data.SetValue("out_trade_no", out_trade_no);
            WxPayData result = WxPayApi.OrderQuery(data);//提交订单查询请求给API,接收返回数据

            //appid=wx3dd4d4698955cef3<br>attach=wx20171129171510297580<br>bank_type=CFT<br>cash_fee=1<br>fee_type=CNY<br>is_subscribe=Y<br>mch_id=1314471801<br>nonce_str=i1Kr0FZp6v5zUgY4<br>openid=opsTsvvf2DWDYhJWiRiGmcJF5uWQ<br>out_trade_no=131447180120171129171510327<br>result_code=SUCCESS<br>return_code=SUCCESS<br>return_msg=OK<br>sign=F57273F59E2470DAB0B01EDB4615DDD6<br>time_end=20171129171528<br>total_fee=1<br>trade_state=SUCCESS<br>trade_type=NATIVE<br>transaction_id=4200000015201711297852647372<br>

            #region 扫码之后所做操作(验证订单是否支付成功+修改订单状态)
            Dictionary <string, string> dic = new Dictionary <string, string>();
            var      WxPayDataStr           = result.ToPrintStr();
            string[] arr = WxPayDataStr.Split(new string[1] {
                "<br>"
            }, StringSplitOptions.RemoveEmptyEntries);
            if (arr.Length > 1)
            {
                for (int i = 0; i < arr.Length; i++)
                {
                    if (!string.IsNullOrEmpty(arr[i]) && arr[i].Length > 0)
                    {
                        var arr1 = arr[i].Split('=');
                        dic.Add(arr1[0], arr1[1]);
                    }
                }
                if (dic.Keys.Contains("trade_state_desc") && dic["trade_state_desc"] == "订单未支付")
                {
                    //订单尚未支付
                    return("notpay");
                }
                else
                {
                    string back_out_trade_no   = dic["out_trade_no"];
                    string back_total_fee      = dic["total_fee"];
                    string back_transaction_id = dic["transaction_id"];
                    //订单支付成功(更新count+改订单状态)
                }
                return("");
            }
            else
            {
                return("");
            }
            #endregion
        }
        private void Timer_Tick(object sender, EventArgs e)
        {
            WxPayData date = new WxPayAPI.WxPayData();

            date.SetValue("out_trade_no", out_trade_no);//公众账号ID

            WxPayData result = WxPayApi.OrderQuery(date);

            if (result.GetValue("return_code").ToString().ToUpper().Equals("SUCCESS"))
            {
                if (result.GetValue("result_code").ToString().ToUpper().Equals("SUCCESS") &&
                    result.GetValue("trade_state").ToString().ToUpper().Equals("SUCCESS"))
                {
                    CloseThis();
                    MessageBox.Show("付款成功");
                }
            }
        }
Exemple #20
0
 /// <summary>
 /// 查询订单的支付结果
 /// </summary>
 /// <param name="orderId">订单编号</param>
 /// <param name="tradeNo">交易流水号</param>
 /// <returns></returns>
 public string Query(string orderId = "", string tradeNo = "")
 {
     try
     {
         var reqData = new WxPayData();
         reqData.SetValue("out_trade_no", orderId);
         reqData.SetValue("transaction_id", tradeNo);
         var queryData = WxPayApi.OrderQuery(reqData);
         var jsonStr   = queryData.ToJson();
         var json      = Newtonsoft.Json.Linq.JObject.Parse(jsonStr);
         jsonStr = JsonHelper.Serialize(json, true);
         return(jsonStr);
     }
     catch (Exception ex)
     {
         return("系统执行时发生异常:" + ex.Message);
     }
 }
Exemple #21
0
        /***
         * 订单查询完整业务流程逻辑
         * @param transaction_id 微信订单号(优先使用)
         * @param out_trade_no 商户订单号
         * @return 订单查询结果(xml格式)
         */
        public static string Run(string transaction_id, string out_trade_no)
        {
            Log.Info("OrderQuery", "OrderQuery is processing...");

            WxPayData data = new WxPayData();

            if (!string.IsNullOrEmpty(transaction_id))//如果微信订单号存在,则以微信订单号为准
            {
                data.SetValue("transaction_id", transaction_id);
            }
            else//微信订单号不存在,才根据商户订单号去查单
            {
                data.SetValue("out_trade_no", out_trade_no);
            }

            WxPayData result = WxPayApi.OrderQuery(data);//提交订单查询请求给API,接收返回数据

            Log.Info("OrderQuery", "OrderQuery process complete, result : " + result.ToXml());
            return(result.ToPrintStr());
        }
Exemple #22
0
        /// <summary>
        /// 订单查询
        /// </summary>
        /// <param name="requestModel">请求实体</param>
        /// <returns></returns>
        public static OrderQueryResponseModel OrderQuery(OrderQueryModel requestModel)
        {
            WxPayData data = new WxPayData();

            if (!string.IsNullOrEmpty(requestModel.transaction_id))
            {//如果微信订单号存在,则以微信订单号为准
                data.SetValue("transaction_id", requestModel.transaction_id);
            }
            else
            {//微信订单号不存在,才根据商户订单号去查单
                data.SetValue("out_trade_no", requestModel.out_trade_no);
            }
            LogUtil.WriteWxpayLog("订单查询请求", "请求参数", data.ToJson());
            //提交订单查询请求给API,接收返回数据
            WxPayData result = WxPayApi.OrderQuery(data);
            OrderQueryResponseModel response = LitJson.JsonMapper.ToObject <OrderQueryResponseModel>(result.ToJson());

            LogUtil.WriteWxpayLog("订单查询响应", "响应参数", result.ToJson());
            //Log.Info("OrderQuery", "OrderQuery process complete, result : " + result.ToXml());
            return(response);
        }
Exemple #23
0
        public override PaymentStatusResponse EnquireStatus(PaymentRequest request, RenderContext context)
        {
            PaymentStatusResponse result = new PaymentStatusResponse();

            var setting = this.GetSetting(context);

            if (request == null || request.Id == default(Guid) || setting == null)
            {
                return(result);
            }

            try
            {
                var data = new WxPayData();
                data.SetValue("out_trade_no", request.Id.ToString("N"));
                var response = WxPayApi.OrderQuery(data, setting);

                var trade_state = response.GetValue("trade_state");
                //trade_state:SUCCESS,REFUND,NOTPAY,CLOSED,REVOKED,USERPAYING,PAYERROR

                if (trade_state != null)
                {
                    result.HasResult = true;
                    var code = trade_state.ToString().ToUpper();
                    if (code == "SUCCESS")
                    {
                        result.IsPaid = true;
                    }
                    else
                    {
                        result.IsCancel = true;
                    }
                }
            }
            catch (Exception ex)
            {
            }

            return(result);
        }
Exemple #24
0
        public string WxNotify()
        {
            WxPayData notify = YiWei.WeiXin.Domain.WXPay.WxNotify.GetNotify();

            //检查支付结果中transaction_id是否存在
            if (!notify.IsSet("transaction_id"))
            {
                var res = new WxPayData();
                res.SetValue("return_code", "FAIL");
                res.SetValue("return_msg", "支付结果中微信订单号不存在");
                return(res.ToXml());
            }
            //再次跟微信查询订单
            WxPayData check = WxPayApi.OrderQuery(notify.GetValue("transaction_id").ToString());

            if (check.GetValue("return_code").ToString().ToUpper() != "SUCCESS" ||
                check.GetValue("result_code").ToString().ToUpper() != "SUCCESS")
            {
                var res = new WxPayData();
                res.SetValue("return_code", "FAIL");
                res.SetValue("return_msg", "订单查询失败");
                return(res.ToXml());
            }

            decimal totalFee = decimal.Parse(notify.GetValue("total_fee").ToString());
            string  openId   = notify.GetValue("openid").ToString();
            string  orderNo  = notify.GetValue("out_trade_no").ToString();
            string  code     = notify.GetValue("attach").ToString();
            //TODO 更新状态
            //TODO 发送消息

            WxPayData result = new WxPayData();

            result.SetValue("return_code", "SUCCESS");
            result.SetValue("return_msg", "OK");
            return(result.ToXml());
        }
Exemple #25
0
        /**
         *
         * 查询订单情况
         * @param string out_trade_no  商户订单号
         * @param int succCode         查询订单结果:0表示订单不成功,1表示订单成功,2表示继续查询
         * @return 订单查询接口返回的数据,参见协议接口
         */
        public WxPayData Query(string out_trade_no, out int succCode)
        {
            WxPayData queryOrderInput = new WxPayData();

            queryOrderInput.SetValue("out_trade_no", out_trade_no);
            WxPayData result = WxPayApi.OrderQuery(queryOrderInput);

            if (result.GetValue("return_code").ToString() == "SUCCESS" &&
                result.GetValue("result_code").ToString() == "SUCCESS")
            {
                //支付成功
                if (result.GetValue("trade_state").ToString() == "SUCCESS")
                {
                    succCode = 1;
                    return(result);
                }
                //用户支付中,需要继续查询
                else if (result.GetValue("trade_state").ToString() == "USERPAYING")
                {
                    succCode = 2;
                    return(result);
                }
            }

            //如果返回错误码为“此交易订单号不存在”则直接认定失败
            if (result.GetValue("err_code").ToString() == "ORDERNOTEXIST")
            {
                succCode = 0;
            }
            else
            {
                //如果是系统错误,则后续继续
                succCode = 2;
            }
            return(result);
        }
Exemple #26
0
        public static string wxPayOrderQuery(string out_trade_no, string appid, string mchid)
        {
            WxPayData data = new WxPayData();

            if (!string.IsNullOrEmpty(out_trade_no))//如果微信订单号存在,则以微信订单号为准
            {
                data.SetValue("out_trade_no", out_trade_no);
            }
            else
            {
                throw new WxPayException("订单查询接口中,out_trade_no填一个!");
            }

            WxPayData result = WxPayApi.OrderQuery(data, appid, mchid);//提交订单查询请求给API,接收返回数据

            if (result.IsSet("result_code") && result.GetValue("result_code").ToString() == "SUCCESS" && result.IsSet("trade_state") && result.GetValue("trade_state").ToString() == "SUCCESS")
            {
                return(result.GetValue("time_end").ToString());
            }
            else
            {
                return(null);
            }
        }
Exemple #27
0
        private bool QueryOrder(string transactionId)
        {
            var config = _configService.Get <WeiXinConfig>();

            WeiXinPayConfig weiXinPayConfig = new WeiXinPayConfig()
            {
                APPID = config.AppId, MCHID = config.MchId, KEY = config.Key
            };

            WxPayData req = new WxPayData();

            req.SetValue("transaction_id", transactionId);
            WxPayData res = WxPayApi.OrderQuery(weiXinPayConfig, req);

            if (res.GetValue("return_code").ToString() == "SUCCESS" &&
                res.GetValue("result_code").ToString() == "SUCCESS")
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #28
0
        public string SearchBankOrder(string CommunityId, string out_trade_no)
        {
            string Result = "";

            WxPayConfig          wxPayConfig = GenerateConfig(CommunityId);
            string               strcon      = PubConstant.GetConnectionString("APPConnection");
            IDbConnection        conn        = new SqlConnection(strcon);
            string               query       = "SELECT * FROM Tb_OL_WeiXinPayOrder WHERE out_trade_no=@out_trade_no";
            Tb_OL_WeiXinPayOrder T_Order     = conn.Query <Tb_OL_WeiXinPayOrder>(query, new { out_trade_no = out_trade_no }).SingleOrDefault();

            if (T_Order == null)
            {
                Result = "未找到该物业订单";
                return(Result);
            }

            WxPayData data = new WxPayData();

            data.SetValue("out_trade_no", out_trade_no);
            WxPayData BankResult = WxPayApi.OrderQuery(data);//提交订单查询请求给API,接收返回数据

            Result = BankResult.GetValue("trade_state").ToString();
            return(Result);
        }
Exemple #29
0
        /// <summary>
        /// 检查订单状态
        /// </summary>
        /// <param name="parameter"></param>
        /// <param name="config"></param>
        /// <returns>只要有结果,无论成功或者失败,返回true,不确定支付结果返回false</returns>
        bool checkPayStateByConfig(PayParameter parameter, WxPayConfig config)
        {
            try
            {
                WxPayData queryOrderInput = new WxPayData();
                queryOrderInput.SetValue("out_trade_no", parameter.TradeID);
                WxPayData result = WxPayApi.OrderQuery(queryOrderInput, config);
                string    xml    = result.ToXml();

                PayFactory.OnLog(parameter.TradeID, xml);
                if (result.GetValue("return_code").ToString() == "SUCCESS" &&
                    result.GetValue("result_code").ToString() == "SUCCESS")
                {
                    //支付成功
                    if (result.GetValue("trade_state").ToString() == "SUCCESS")
                    {
                        //触发回调函数
                        PayFactory.OnPaySuccessed(parameter.TradeID, result.ToXml());
                        return(true);
                    }
                    //用户支付中,需要继续查询
                    else if (result.GetValue("trade_state").ToString() == "USERPAYING")
                    {
                        return(false);
                    }
                    else if (result.GetValue("trade_state").ToString() == "NOTPAY")
                    {
                        //触发回调函数
                        PayFactory.OnPayFailed(parameter.TradeID, "放弃支付", xml);
                        return(true);
                    }
                }

                string returnMsg = result.GetValue("err_code_des").ToSafeString();
                if (string.IsNullOrEmpty(returnMsg))
                {
                    returnMsg = result.GetValue("return_msg").ToSafeString();
                }

                //如果返回错误码为“此交易订单号不存在”,直接失败
                if (result.GetValue("err_code").ToString() == "ORDERNOTEXIST")
                {
                    //触发回调函数
                    PayFactory.OnPayFailed(parameter.TradeID, returnMsg, xml);
                    return(true);
                }
                else if (result.GetValue("err_code").ToString() == "SYSTEMERROR")
                {
                    //如果是系统错误,则后续继续
                    return(false);
                }
                else if (result.GetValue("return_code").ToString() == "FAIL" ||
                         result.GetValue("result_code").ToString() == "FAIL")
                {
                    //FAIL
                    //触发回调函数
                    PayFactory.OnPayFailed(parameter.TradeID, returnMsg, xml);
                    return(true);
                }
            }
            catch
            {
            }
            return(false);
        }
        /// <summary>
        /// 2-付款成功 1-未付款 3-异常
        /// </summary>
        /// <param name="out_trade_no"></param>
        /// <returns></returns>
        public static int OrderQuery(string out_trade_no)
        {
            var exist_payment = Foresight.DataAccess.Payment.GetPaymentByTradeNo(out_trade_no);

            if (exist_payment == null)
            {
                return(1);
            }
            if (string.IsNullOrEmpty(exist_payment.PaymentType))
            {
                return(1);
            }
            if (exist_payment.PaymentType.Equals(Utility.EnumModel.PaymentTypeDefine.wx.ToString()))
            {
                if (exist_payment.Status == 2)
                {
                    Web.APPCode.PaymentHelper.SaveRoomFee(out_trade_no, "微信公众号微信支付", "微信支付");
                    return(2);
                }
                WxPayData data = new WxPayData();
                data.SetValue("out_trade_no", out_trade_no);
                WxPayData result      = WxPayApi.OrderQuery(data);//提交订单查询请求给API,接收返回数据
                var       sort_list   = data.FromXml(result.ToXml());
                var       trade_state = result.GetValue("trade_state");
                if (trade_state != null && trade_state.ToString() == "SUCCESS")
                {
                    Web.APPCode.PaymentHelper.SaveRoomFee(out_trade_no, "微信公众号微信支付", "微信支付");
                    return(2);
                }
                return(1);
            }
            if (exist_payment.PaymentType.Equals(Utility.EnumModel.PaymentTypeDefine.alipay.ToString()))
            {
                if (exist_payment.Status == 2)
                {
                    Web.APPCode.PaymentHelper.SaveRoomFee(out_trade_no, "微信公众号支付宝支付", "支付宝");
                    return(2);
                }
                return(AlipayOrderQuery(out_trade_no));
            }
            if (exist_payment.PaymentType.Equals(Utility.EnumModel.PaymentTypeDefine.app_wx.ToString()))
            {
                if (exist_payment.Status == 2)
                {
                    Web.APPCode.PaymentHelper.SaveRoomFee(out_trade_no, "APP微信支付", "微信支付");
                    return(2);
                }
                WxPayData data = new WxPayData();
                data.SetValue("out_trade_no", out_trade_no);
                WxPayData result      = WxPayApi.OrderQueryAPP(data);//提交订单查询请求给API,接收返回数据
                var       sort_list   = data.FromXml(result.ToXml());
                var       trade_state = result.GetValue("trade_state");
                if (trade_state != null && trade_state.ToString() == "SUCCESS")
                {
                    Web.APPCode.PaymentHelper.SaveRoomFee(out_trade_no, "APP微信支付", "微信支付");
                    return(2);
                }
                return(1);
            }
            if (exist_payment.PaymentType.Equals(Utility.EnumModel.PaymentTypeDefine.app_alipay.ToString()))
            {
                if (exist_payment.Status == 2)
                {
                    Web.APPCode.PaymentHelper.SaveRoomFee(out_trade_no, "APP支付宝支付", "支付宝");
                    return(2);
                }
                return(AlipayAPPOrderQuery(out_trade_no));
            }
            return(1);
        }