コード例 #1
0
ファイル: Pay_OrderBll.cs プロジェクト: kucenchen/ASP.NET
        /// <summary>
        /// 通知接口
        /// </summary>
        /// <param name="pid"></param>
        /// <param name="mid"></param>
        /// <param name="Request"></param>
        /// <returns></returns>
        public async Task <NotifyReturn> Notify(int pid, int mid, Microsoft.AspNetCore.Http.HttpRequest Request)
        {
            Pay_plat  p         = OnlinePay.GetPlat(pid);
            Pay_mch   m         = OnlinePay.GetMch(mid);
            OnlinePay onlinepay = (OnlinePay)Activator.CreateInstance(Type.GetType(p.Plat_class), p, m);

            NotifyReturn r = await onlinepay.Notify(Request);

            if (r.IsCheck)
            {
                if (r.IsPay)
                {
                    Pay_order order = DB.Context.From <Pay_order>().Where(o => o.Order_id == r.OrderNumber).ToFirstDefault();

                    if (order != null && !string.IsNullOrEmpty(order.Order_id))
                    {
                        if (order.Status == 0)
                        {
                            order.Status          = 1;
                            order.Finish_time     = DateTime.Now.ToTimeStamp();
                            order.Pay_amount      = r.Totalfee;
                            order.Notify_status   = 0;
                            order.Notify_times    = 0;
                            order.Notify_lasttime = DateTime.Now.ToTimeStamp();
                            DB.Context.Save(order);
                        }
                    }
                }
                return(r);
            }
            else
            {
                return(r);
            }
        }
コード例 #2
0
ファイル: PayOrderBll.cs プロジェクト: kucenchen/ASP.NET
        /// <summary>
        /// 回调接口
        /// </summary>
        /// <param name="pid"></param>
        /// <param name="mid"></param>
        /// <param name="Request"></param>
        /// <param name="Response"></param>
        /// <returns></returns>
        public async Task <NotifyReturnModel> CallBack(int pid, int mid, Microsoft.AspNetCore.Http.HttpRequest Request, Microsoft.AspNetCore.Http.HttpResponse Response)
        {
            PayPlat   p         = OnlinePay.GetPlat(pid);
            PayMch    m         = OnlinePay.GetMch(mid);
            OnlinePay onlinepay = (OnlinePay)Activator.CreateInstance(Type.GetType(p.Plat_class), p, m);

            NotifyReturnModel r = await onlinepay.CallBack(Request);

            if (r.IsCheck)
            {
                if (r.IsPay)
                {
                    PayOrder order = DbContext._.Db.From <PayOrder>().Where(o => o.Order_id == r.OrderNumber).ToFirstDefault();

                    if (order != null && string.IsNullOrEmpty(order.Order_id))
                    {
                        if (order.Status == 0)
                        {
                            order.Attach(EntityState.Modified);
                            order.Status          = 1;
                            order.Finish_time     = DateTime.Now.ToTimeStamp();
                            order.Pay_amount      = r.Totalfee;
                            order.Notify_status   = 0;
                            order.Notify_times    = 0;
                            order.Notify_lasttime = DateTime.Now.ToTimeStamp();
                            DbContext._.Db.Save(order);
                        }
                    }
                }
            }

            if (string.IsNullOrEmpty(r.OrderNumber))
            {
                PayOrder order = DbContext._.Db.From <PayOrder>().Where(o => o.Order_id == r.OrderNumber).ToFirstDefault();

                if (order != null && !string.IsNullOrEmpty(order.Order_id) && !string.IsNullOrEmpty(order.Callback_url))
                {
                    SortedDictionary <string, string> para = new SortedDictionary <string, string>();

                    para.Add("mchid", WebConfig.MchId);
                    para.Add("orderid", order.Order_id);
                    para.Add("serialid", order.Plat_order_id);
                    para.Add("amount", order.Pay_amount.ToString());
                    para.Add("attach", order.Attach);
                    para.Add("status", order.Status.ToString());

                    string sign = string.Format("{0}&key={1}", OnlinePay.GetParamSrc(para), WebConfig.MchKey);
                    sign = Dos.Common.EncryptHelper.MD5EncryptWeChat(sign, "utf-8");

                    para.Add("sign", sign);

                    Response.Redirect(string.Format("{0}?{1}", order.Callback_url, OnlinePay.GetParamSrc(para)));
                }
            }
            return(r);
        }
コード例 #3
0
ファイル: PayOrderBll.cs プロジェクト: kucenchen/ASP.NET
        /// <summary>
        /// 通知接口
        /// </summary>
        /// <param name="pid"></param>
        /// <param name="mid"></param>
        /// <param name="Request"></param>
        /// <returns></returns>
        public async Task <NotifyReturnModel> Notify(int pid, int mid, Microsoft.AspNetCore.Http.HttpRequest Request)
        {
            NotifyReturnModel r = null;

            try
            {
                PayPlat   p         = OnlinePay.GetPlat(pid);
                PayMch    m         = OnlinePay.GetMch(mid);
                OnlinePay onlinepay = (OnlinePay)Activator.CreateInstance(Type.GetType(p.Plat_class), p, m);
                r = await onlinepay.Notify(Request);
            }
            catch (Exception ex)
            {
                Dos.Common.LogHelper.Debug("第三方回调初始化失败:" + ex.Message);
                throw ex;
            }


            if (r.IsCheck)
            {
                if (r.IsPay)
                {
                    PayOrder order = DbContext._.Db.From <PayOrder>().Where(o => o.Order_id == r.OrderNumber).ToFirstDefault();

                    if (order != null && !string.IsNullOrEmpty(order.Order_id))
                    {
                        if (order.Status == 0)
                        {
                            order.Attach(EntityState.Modified);
                            order.Status          = 1;
                            order.Finish_time     = DateTime.Now.ToTimeStamp();
                            order.Pay_amount      = r.Totalfee;
                            order.Notify_status   = 0;
                            order.Notify_times    = 0;
                            order.Notify_lasttime = DateTime.Now.ToTimeStamp();
                            order.Plat_order_id   = r.SerialNumber;
                            int res = DbContext._.Db.Save(order);
                        }
                    }
                }
                return(r);
            }
            else
            {
                return(r);
            }
        }
コード例 #4
0
ファイル: Pay_OrderBll.cs プロジェクト: kucenchen/ASP.NET
        /// <summary>
        /// 查询接口
        /// </summary>
        /// <param name="mchid"></param>
        /// <param name="orderid"></param>
        /// <param name="sign"></param>
        /// <returns></returns>
        public async Task <QueryReturn> Query(string mchid, string orderid)
        {
            QueryReturn r = new QueryReturn();



            if (mchid != DB.MchId)
            {
                r.ReturnMsg = "商户号不存在";
                return(r);
            }


            Pay_order order = DB.Context.From <Pay_order>().Where(p => p.Order_id == orderid).ToFirstDefault();

            if (order == null || string.IsNullOrEmpty(order.Order_id))
            {
                r.ReturnMsg = "订单不存在";
                return(r);
            }



            if (order.Status == 1)
            {
                r.ReturnMsg    = "ok";
                r.IsPay        = true;
                r.OrderNumber  = order.Order_id;
                r.SerialNumber = order.Plat_order_id;
                r.Totalfee     = order.Pay_amount;
                r.Attach       = order.Attach;
                return(r);
            }
            else
            {
                Pay_mch mch = OnlinePay.GetMch(order.Mch_id);

                if (mch == null)
                {
                    r.ReturnMsg = "平台商户信息错误";
                    return(r);
                }

                Pay_plat plat = OnlinePay.GetPlat(mch.Plat_id);
                if (plat == null)
                {
                    r.ReturnMsg = "平台渠道信息错误";
                    return(r);
                }

                OnlinePay onlinepay = (OnlinePay)Activator.CreateInstance(Type.GetType(plat.Plat_class), plat, mch);


                r = await onlinepay.OrderQuery(order.Order_id);

                if (r.ReturnMsg == "ok" && r.IsPay)
                {
                    order.Status = 1;
                    if (r.Totalfee > 0)
                    {
                        order.Pay_amount = r.Totalfee;
                    }

                    order.Finish_time = DateTime.Now.ToTimeStamp();

                    DB.Context.Save(order);
                }

                return(r);
            }
        }
コード例 #5
0
ファイル: PayOrderBll.cs プロジェクト: kucenchen/ASP.NET
        /// <summary>
        /// 查询接口
        /// </summary>
        /// <param name="mchid"></param>
        /// <param name="orderid"></param>
        /// <param name="sign"></param>
        /// <returns></returns>
        public async Task <QueryReturnModel> Query(string mchid, string orderid)
        {
            QueryReturnModel r = new QueryReturnModel();

            if (mchid != WebConfig.MchId)
            {
                Dos.Common.LogHelper.Debug("商户号不存在");
                r.ReturnMsg = "商户号不存在";
                return(r);
            }

            PayOrder order = DbContext._.Db.From <PayOrder>().Where(p => p.Order_id == orderid.SqlFilters()).ToFirstDefault();

            if (order == null || string.IsNullOrEmpty(order.Order_id))
            {
                Dos.Common.LogHelper.Debug("订单不存在");
                r.ReturnMsg = "订单不存在";
                return(r);
            }
            if (order.Status == 1)
            {
                r.ReturnMsg    = "ok";
                r.IsPay        = true;
                r.OrderNumber  = order.Order_id;
                r.SerialNumber = order.Plat_order_id;
                r.Totalfee     = order.Pay_amount;
                r.Attach       = order.Attach;
                return(r);
            }
            else
            {
                PayMch mch = OnlinePay.GetMch(order.Mch_id);

                if (mch == null)
                {
                    Dos.Common.LogHelper.Debug("平台商户信息错误");
                    r.ReturnMsg = "平台商户信息错误";
                    return(r);
                }

                PayPlat plat = OnlinePay.GetPlat(mch.Plat_id);
                if (plat == null)
                {
                    Dos.Common.LogHelper.Debug("平台渠道信息错误");
                    r.ReturnMsg = "平台渠道信息错误";
                    return(r);
                }
                try
                {
                    OnlinePay onlinepay = (OnlinePay)Activator.CreateInstance(Type.GetType(plat.Plat_class), plat, mch);

                    r = await onlinepay.OrderQuery(order.Order_id);
                }
                catch (Exception ex)
                {
                    Dos.Common.LogHelper.Debug("第三方查询下单失败1:" + ex.Message);
                    throw ex;
                }

                try
                {
                    if (r.ReturnMsg == "ok" && r.IsPay)
                    {
                        order.Attach(EntityState.Modified);
                        order.Status = 1;
                        if (r.Totalfee > 0)
                        {
                            order.Pay_amount = r.Totalfee;
                        }

                        order.Finish_time = DateTime.Now.ToTimeStamp();
                        DbContext._.Db.Save(order);
                    }
                    else
                    {
                        Dos.Common.LogHelper.Debug("第三方查询结果:ReturnMsg " + r.ReturnMsg + "## IsPay " + r.IsPay);
                    }
                }
                catch (Exception ex)
                {
                    Dos.Common.LogHelper.Debug("第三方查询下单失败2:" + ex.Message);
                    throw ex;
                }

                return(r);
            }
        }