Exemple #1
0
        public OnlineSettle(Settle_plat p, Settle_mch m)
        {
            if (p == null)
            {
                return;
            }

            if (m == null)
            {
                return;
            }
            this.Plat.Id             = p.Plat_id;
            this.Plat.Name           = p.Plat_name;
            this.Plat.Settle_gateway = p.Pay_gateway;
            this.Plat.Bank_list      = p.Banklist;
            this.Plat.Req_gateway    = p.Req_gateway;
            this.Plat.Class          = p.Plat_class;
            this.Callback_Host       = m.Callback_host;
            this.ID      = m.Id;
            this.MchID   = m.Mch_id;
            this.MchKey  = m.Mch_key;
            this.MchKey2 = m.Mch_key2;
            this.MchName = m.Mch_name;
            this.Plat_Id = m.Plat_id;

            //this = (OnlinePay)Activator.CreateInstance(Type.GetType(this.Plat.Class));
        }
Exemple #2
0
        public OnlineSettle(int plat, string mchid)
        {
            Settle_plat p = PlatList.Find(pp => pp.Plat_id == plat);

            if (p == null || p.Plat_id != plat)
            {
                return;
            }
            Settle_mch m = MchList.Find(mm => mm.Plat_id == plat && mm.Mch_id == mchid);

            if (m == null || m.Plat_id != plat || m.Mch_id != mchid)
            {
                return;
            }
            this.Plat.Id             = p.Plat_id;
            this.Plat.Name           = p.Plat_name;
            this.Plat.Settle_gateway = p.Pay_gateway;
            this.Plat.Bank_list      = p.Banklist;
            this.Plat.Req_gateway    = p.Req_gateway;
            this.Plat.Class          = p.Plat_class;
            this.Callback_Host       = m.Callback_host;
            this.ID      = m.Id;
            this.MchID   = m.Mch_id;
            this.MchKey  = m.Mch_key;
            this.MchKey2 = m.Mch_key2;
            this.MchName = m.Mch_name;
            this.Plat_Id = m.Plat_id;
        }
Exemple #3
0
        /// <summary>
        /// 回调接口
        /// </summary>
        /// <param name="pid"></param>
        /// <param name="mid"></param>
        /// <param name="Request"></param>
        /// <param name="Response"></param>
        /// <returns></returns>
        public async Task <NotifyReturn> CallBack(int pid, int mid, Microsoft.AspNetCore.Http.HttpRequest Request, Microsoft.AspNetCore.Http.HttpResponse Response)
        {
            Settle_plat  p         = OnlineSettle.GetPlat(pid);
            Settle_mch   m         = OnlineSettle.GetMch(mid);
            OnlineSettle onlinepay = (OnlineSettle)Activator.CreateInstance(Type.GetType(p.Plat_class), p, m);

            NotifyReturn r = await onlinepay.CallBack(Request);

            if (r.IsCheck)
            {
                if (r.IsPay)
                {
                    Settle_order order = DB.Context.From <Settle_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();
                            order.Returnmsg       = r.ReturnMsg;
                            DB.Context.Save(order);
                        }
                    }
                }
            }

            if (string.IsNullOrEmpty(r.OrderNumber))
            {
                Settle_order order = DB.Context.From <Settle_order>().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", DB.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), DB.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 #4
0
        /// <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)
        {
            Settle_plat  p         = OnlineSettle.GetPlat(pid);
            Settle_mch   m         = OnlineSettle.GetMch(mid);
            OnlineSettle onlinepay = (OnlineSettle)Activator.CreateInstance(Type.GetType(p.Plat_class), p, m);

            NotifyReturn r = await onlinepay.Notify(Request);

            if (r.IsCheck)
            {
                if (r.IsPay)
                {
                    Settle_order order = DB.Context.From <Settle_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();
                            order.Returnmsg       = r.ReturnMsg;
                            DB.Context.Save(order);
                        }
                    }
                }
                else
                {
                    Settle_order order = DB.Context.From <Settle_order>().Where(o => o.Order_id == r.OrderNumber).ToFirstDefault();

                    if (order != null && !string.IsNullOrEmpty(order.Order_id))
                    {
                        if (order.Status == 0)
                        {
                            order.Returnmsg = r.ReturnMsg;
                            DB.Context.Save(order);
                        }
                    }
                }
                return(r);
            }
            else
            {
                return(r);
            }
        }
Exemple #5
0
        /// <summary>
        /// 统一下单
        /// </summary>
        /// <param name="mchid"></param>
        /// <param name="orderid"></param>
        /// <param name="body"></param>
        /// <param name="paytype"></param>
        /// <param name="amount"></param>
        /// <param name="attach"></param>
        /// <param name="ip"></param>
        /// <param name="callbackurl"></param>
        /// <param name="notifyurl"></param>
        /// <param name="sign"></param>
        /// <returns></returns>
        public async Task <UnifiedorderReturn> Unifiedorder(string mchid, string orderid, string Bank_name, string Bank_branch, string Bank_card_number, string Bank_account, string amount, string attach, string ip, string callbackurl, string notifyurl)
        {
            UnifiedorderReturn r = new UnifiedorderReturn();

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


            decimal fee = 0;

            decimal.TryParse(amount, out fee);

            if (fee <= 0)
            {
                r.Type    = PayReturnType.Err;
                r.Content = "打款金额必须大于0";
                return(r);
            }

            Settle_mch m = OnlineSettle.MchList.FindAll(pp => pp.Nullity == false && ("" + pp.BankList + ",").Contains("," + Bank_name.Trim() + ",") &&
                                                        (pp.Max_money == 0 || pp.Max_money >= fee) && (pp.Min_money == 0 || pp.Min_money <= fee)).OrderBy(i => Guid.NewGuid()).First();

            if (m == null)
            {
                r.Type    = PayReturnType.Err;
                r.Content = "平台没有可用的打款渠道";
                return(r);
            }

            Settle_plat p = OnlineSettle.GetPlat(m.Plat_id);

            if (p == null)
            {
                r.Type    = PayReturnType.Err;
                r.Content = "平台支付渠道有误";
                return(r);
            }

            if (DB.Context.Exists <Settle_order>(o => o.Order_id == orderid))
            {
                r.Type    = PayReturnType.Err;
                r.Content = "订单号已经存在";
                return(r);
            }

            Settle_order order = new Settle_order();

            order.Order_id         = orderid;
            order.Mch_id           = m.Id;
            order.Order_amount     = fee;
            order.Pay_amount       = 0;
            order.Bank_name        = Bank_name.Trim();
            order.Bank_branch      = Bank_branch.Trim();
            order.Bank_card_number = Bank_card_number.Trim();
            order.Bank_account     = Bank_account.Trim();
            order.Status           = 0;
            order.Callback_url     = callbackurl;
            order.Notify_url       = notifyurl;
            order.Create_time      = DateTime.Now.ToTimeStamp();
            order.Update_time      = order.Create_time;
            order.Finish_time      = order.Update_time;
            order.Notify_status    = 0;
            order.Notify_lasttime  = order.Update_time;
            order.Notify_times     = 0;
            order.Attach           = attach;


            OnlineSettle onlinepay = (OnlineSettle)Activator.CreateInstance(Type.GetType(p.Plat_class), p, m);


            r = await onlinepay.Unifiedorder(orderid, Bank_name, Bank_branch, Bank_card_number, Bank_account, fee, ip, attach);

            if (r.Type != 0)
            {
                order.Plat_order_id = r.SerialNumber;
                order.Pay_amount    = decimal.Parse(r.RealPrice);
                order.Returnmsg     = r.Content;
            }

            DB.Context.Save(order);
            return(r);
        }
Exemple #6
0
        /// <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);
            }


            Settle_order order = DB.Context.From <Settle_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
            {
                Settle_mch mch = OnlineSettle.GetMch(order.Mch_id);

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

                Settle_plat 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)
                {
                    order.Status = 1;
                    if (r.Totalfee > 0)
                    {
                        order.Pay_amount = r.Totalfee;
                    }

                    order.Finish_time = DateTime.Now.ToTimeStamp();
                    order.Returnmsg   = r.ReturnMsg;
                    DB.Context.Save(order);
                }
                else
                {
                    order.Returnmsg = r.ReturnMsg;
                    DB.Context.Save(order);
                }

                return(r);
            }
        }