Exemple #1
0
        /// <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)
        {
            SettlePlat   p         = OnlineSettle.GetPlat(pid);
            SettleMch    m         = OnlineSettle.GetMch(mid);
            OnlineSettle onlinepay = (OnlineSettle)Activator.CreateInstance(Type.GetType(p.Plat_class), p, m);

            NotifyReturnModel r = await onlinepay.CallBack(Request);

            if (r.IsCheck)
            {
                if (r.IsPay == 1)
                {
                    SettleOrder order = DbContext._.Db.From <SettleOrder>().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.Returnmsg       = r.ReturnMsg;
                            DbContext._.Db.Save(order);
                        }
                    }
                }
            }

            if (string.IsNullOrEmpty(r.OrderNumber))
            {
                SettleOrder order = DbContext._.Db.From <SettleOrder>().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}", OnlineSettle.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, OnlineSettle.GetParamSrc(para)));
                }
            }
            return(r);
        }
Exemple #2
0
        /// <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)
        {
            SettlePlat   p         = OnlineSettle.GetPlat(pid);
            SettleMch    m         = OnlineSettle.GetMch(mid);
            OnlineSettle onlinepay = (OnlineSettle)Activator.CreateInstance(Type.GetType(p.Plat_class), p, m);

            NotifyReturnModel r = await onlinepay.Notify(Request);

            if (r.IsCheck)
            {
                if (r.IsPay == 1)
                {
                    SettleOrder order = DbContext._.Db.From <SettleOrder>().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;
                            order.Returnmsg       = r.ReturnMsg;
                            DbContext._.Db.Save(order);
                        }
                    }
                }
                else
                {
                    SettleOrder order = DbContext._.Db.From <SettleOrder>().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.Returnmsg = r.ReturnMsg;
                            DbContext._.Db.Save(order);
                        }
                    }
                }
                return(r);
            }
            else
            {
                return(r);
            }
        }
Exemple #3
0
        /// <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)
            {
                r.ReturnMsg = "商户号不存在";
                return(r);
            }

            SettleOrder order = DbContext._.Db.From <SettleOrder>().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        = 1;
                r.OrderNumber  = order.Order_id;
                r.SerialNumber = order.Plat_order_id;
                r.Totalfee     = order.Pay_amount;
                r.Attach       = order.Attach;
                return(r);
            }
            else
            {
                SettleMch mch = OnlineSettle.GetMch(order.Mch_id);

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

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

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


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

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

                    order.Finish_time = DateTime.Now.ToTimeStamp();
                    order.Returnmsg   = r.ReturnMsg;
                    DbContext._.Db.Save(order);
                }
                else
                {
                    order.Attach(EntityState.Modified);
                    order.Returnmsg = r.ReturnMsg;
                    DbContext._.Db.Save(order);
                }

                return(r);
            }
        }