Esempio n. 1
0
        public ActionResult Detail(string orderId)
        {
            if (LoginHelper.GetCurrentUser() == null)
            {
                return(RedirectToAction("Forbidden", "Base"));
            }
            ViewBag.isShowFooter = false;
            var model = IPayOrderService.Find(orderId);

            if (model != null)
            {
                if (LoginHelper.GetCurrentUser().ID != model.UserID)
                {
                    return(RedirectToAction("Forbidden", "base"));
                }
                if (model.State == PayState.WaitPay)
                {
                    var obj = OrderQuery.Run("", orderId);
                    if (obj.GetValue("trade_state").ToString() == "SUCCESS")
                    {
                        model.State = PayState.Success;
                        IPayOrderService.SuccessPayOrder(orderId, obj.GetValue("transaction_id").ToString());
                    }
                    else
                    {
                        IPayOrderService.FailedPayOrder(orderId);
                    }
                }
                return(View(model));
            }
            else
            {
                return(RedirectToAction("_500", "base"));
            }
        }
Esempio n. 2
0
        public void WxNotify()
        {
            Notify    notify     = new Notify(this.HttpContext);
            WxPayData notifyData = notify.GetNotifyData();

            //检查支付结果中transaction_id是否存在
            if (!notifyData.IsSet("transaction_id"))
            {
                //若transaction_id不存在,则立即返回结果给微信支付后台
                WxPayData res = new WxPayData();
                res.SetValue("return_code", "FAIL");
                res.SetValue("return_msg", "支付结果中微信订单号不存在");
                Response.Write(res.ToXml());
                Response.End();
            }

            string transaction_id = notifyData.GetValue("transaction_id").ToString();

            var model = IPayOrderService.Find(transaction_id);

            if (model == null || model.State != PayState.WaitPay)
            {
                WxPayData res = new WxPayData();
                res.SetValue("return_code", "FAIL");
                res.SetValue("return_msg", "订单查询失败");
                Response.Write(res.ToXml());
                Response.End();
            }

            //查询订单,判断订单真实性
            if (!QueryOrder(transaction_id))
            {
                IPayOrderService.FailedPayOrder(transaction_id);
                //若订单查询失败,则立即返回结果给微信支付后台
                WxPayData res = new WxPayData();
                res.SetValue("return_code", "FAIL");
                res.SetValue("return_msg", "订单查询失败");
                Response.Write(res.ToXml());
                Response.End();
            }
            //查询订单成功
            else
            {
                WxPayData res    = new WxPayData();
                var       result = IPayOrderService.SuccessPayOrder(transaction_id, transaction_id);
                if (result.Result)
                {
                    res.SetValue("return_code", "SUCCESS");
                    res.SetValue("return_msg", "OK");
                }
                else
                {
                    res.SetValue("return_code", "FAIL");
                    res.SetValue("return_msg", "订单修改失败");
                }
                Response.Write(res.ToXml());
                Response.End();
            }
        }