コード例 #1
0
        public async Task <ApiResult <string> > Add(PayPlat parm)
        {
            var queryModel = PayPlatBll._.GetModelAsync(d => d.Plat_name == parm.Plat_name.SqlFilters() || d.Plat_class == parm.Plat_class.SqlFilters()).Result.data;

            if (!string.IsNullOrEmpty(queryModel.Plat_name) || !string.IsNullOrEmpty(queryModel.Plat_class))
            {
                if (queryModel.Plat_name == parm.Plat_name)
                {
                    return(new ApiResult <string>()
                    {
                        statusCode = (int)ApiEnum.Error, message = string.Format("已存在渠道名称'{0}'", parm.Plat_name)
                    });
                }
                else
                {
                    return(new ApiResult <string>()
                    {
                        statusCode = (int)ApiEnum.Error, message = string.Format("已存在渠道类名'{0}'", parm.Plat_class)
                    });
                }
            }
            parm.Plat_name     = parm.Plat_name ?? "";
            parm.Plat_class    = parm.Plat_class ?? "";
            parm.Req_gateway   = parm.Req_gateway ?? "";
            parm.Pay_gateway   = parm.Pay_gateway ?? "";
            parm.Pay_type_list = parm.Pay_type_list ?? "";
            return(await PayPlatBll._.AddAsync(parm));
        }
コード例 #2
0
        public async Task <ApiResult <string> > ModifyPayMch(PayPlat parm)
        {
            var queryModel = PayPlatBll._.GetModelAsync(d => d.Plat_id != parm.Plat_id && (d.Plat_name == parm.Plat_name.SqlFilters() || d.Plat_class == parm.Plat_class.SqlFilters())).Result.data;

            if (!string.IsNullOrEmpty(queryModel.Plat_name) || !string.IsNullOrEmpty(queryModel.Plat_class))
            {
                if (queryModel.Plat_name == parm.Plat_name)
                {
                    return(new ApiResult <string>()
                    {
                        statusCode = (int)ApiEnum.Error, message = string.Format("已存在渠道名称'{0}'", parm.Plat_name)
                    });
                }
                else
                {
                    return(new ApiResult <string>()
                    {
                        statusCode = (int)ApiEnum.Error, message = string.Format("已存在渠道类名'{0}'", parm.Plat_class)
                    });
                }
            }

            Dictionary <Field, object> model = new Dictionary <Field, object>();

            model.Add(PayPlat._.Plat_name, parm.Plat_name.SqlFilters() ?? "");
            model.Add(PayPlat._.Plat_class, parm.Plat_class.SqlFilters() ?? "");
            model.Add(PayPlat._.Req_gateway, parm.Req_gateway.SqlFilters() ?? "");
            model.Add(PayPlat._.Pay_gateway, parm.Pay_gateway.SqlFilters() ?? "");
            model.Add(PayPlat._.Pay_type_list, parm.Pay_type_list.SqlFilters() ?? "");
            return(await PayPlatBll._.UpdateAsync(model, d => d.Plat_id == parm.Plat_id));
        }
コード例 #3
0
ファイル: OnlinePay.cs プロジェクト: kucenchen/ASP.NET
        public OnlinePay(PayPlat p, PayMch m)
        {
            if (p == null)
            {
                return;
            }

            if (m == null)
            {
                return;
            }
            this.Plat               = new PayPlat();
            this.Plat.Plat_id       = p.Plat_id;
            this.Plat.Plat_name     = p.Plat_name;
            this.Plat.Pay_gateway   = p.Pay_gateway;
            this.Plat.Pay_type_list = p.Pay_type_list;
            this.Plat.Req_gateway   = p.Req_gateway;
            this.Plat.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;
        }
コード例 #4
0
ファイル: OnlinePay.cs プロジェクト: kucenchen/ASP.NET
        public OnlinePay(int plat, string mchid)
        {
            PayPlat p = PlatList.Find(pp => pp.Plat_id == plat);

            if (p == null || p.Plat_id != plat)
            {
                return;
            }
            PayMch 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               = new PayPlat();
            this.Plat.Plat_id       = p.Plat_id;
            this.Plat.Plat_name     = p.Plat_name;
            this.Plat.Pay_gateway   = p.Pay_gateway;
            this.Plat.Pay_type_list = p.Pay_type_list;
            this.Plat.Req_gateway   = p.Req_gateway;
            this.Plat.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;
        }
コード例 #5
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);
        }
コード例 #6
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);
            }
        }
コード例 #7
0
 public HengYinPay(PayPlat p, PayMch m) : base(p, m)
 {
 }
コード例 #8
0
ファイル: TestRealPay.cs プロジェクト: kucenchen/ASP.NET
 public TestRealPay(PayPlat p, PayMch m) : base(p, m)
 {
 }
コード例 #9
0
ファイル: LemeiPay.cs プロジェクト: kucenchen/ASP.NET
 public LemeiPay(PayPlat p, PayMch m) : base(p, m)
 {
 }
コード例 #10
0
ファイル: PayOrderBll.cs プロジェクト: kucenchen/ASP.NET
        /// <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 <UnifiedOrderReturnModel> Unifiedorder(string mchid, string orderid, string body, int paytype, string amount, string attach, string ip, string callbackurl, string notifyurl)
        {
            UnifiedOrderReturnModel r = new UnifiedOrderReturnModel();
            //if (mchid != WebConfig.MchId)
            //{
            //    Dos.Common.LogHelper.Debug("商户号不存在");
            //    r.Type = PayReturnTypeEnum.Err;
            //    r.Content = "商户号不存在";
            //    return r;
            //}

            decimal fee = 0;

            decimal.TryParse(amount, out fee);

            if (fee <= 0)
            {
                Dos.Common.LogHelper.Debug("支付金额必须大于0");
                r.Type    = PayReturnTypeEnum.Err;
                r.Content = "支付金额必须大于0";
                return(r);
            }

            PayMch payMchModel = OnlinePay.MchList.FindAll(pp => pp.Nullity == false && ("," + pp.Open_time + ",").Contains("," + DateTime.Now.Hour.ToString() + ",") && ("," + pp.Open_pay_type_list + ",").Contains("," + paytype + ",") && ("," + pp.Pay_money_list + ",").Contains("," + amount + ",")).OrderBy(i => Guid.NewGuid()).FirstOrDefault();

            if (payMchModel == null)
            {
                Dos.Common.LogHelper.Debug("平台没有可用的支付渠道");
                r.Type    = PayReturnTypeEnum.Err;
                r.Content = "平台没有可用的支付渠道";
                return(r);
            }
            //1:随机加减0-9分 2:随机加减0-9元
            if (payMchModel.Israndom == 1)
            {
                int randomNum = new Random().Next(-9, 10);
                if (randomNum != 0)
                {
                    fee += Convert.ToDecimal(randomNum) / 100;
                }
            }
            else if (payMchModel.Israndom == 2)
            {
                int randomNum = new Random().Next(-9, 10);
                if (randomNum != 0)
                {
                    fee += Convert.ToDecimal(randomNum);
                }
            }

            if (fee <= 0)
            {
                Dos.Common.LogHelper.Debug("支付金额必须大于0  2");
                r.Type    = PayReturnTypeEnum.Err;
                r.Content = "支付金额必须大于0";
                return(r);
            }

            PayPlat payPlatModel = OnlinePay.GetPlat(payMchModel.Plat_id);

            if (payPlatModel == null)
            {
                Dos.Common.LogHelper.Debug("平台支付渠道有误");
                r.Type    = PayReturnTypeEnum.Err;
                r.Content = "平台支付渠道有误";
                return(r);
            }

            if (DbContext._.Db.Exists <PayOrder>(d => d.Order_id == orderid.SqlFilters()))
            {
                Dos.Common.LogHelper.Debug("订单号已经存在");
                r.Type    = PayReturnTypeEnum.Err;
                r.Content = "订单号已经存在";
                return(r);
            }

            PayOrder order = new PayOrder();

            order.Order_id        = orderid;
            order.Plat_order_id   = "";
            order.Mch_id          = payMchModel.Id;
            order.Order_amount    = fee;
            order.Pay_amount      = 0;
            order.Pay_type        = paytype;
            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;
            bool isSuccess = false;

            try
            {
                isSuccess = DbContext._.Db.Insert <PayOrder>(order) > 0;
            }
            catch (Exception e)
            {
                Dos.Common.LogHelper.Debug("创建订单失败:" + e.Message);
                string err = e.Message;
                throw;
            }

            if (!isSuccess)
            {
                Dos.Common.LogHelper.Debug("创建订单失败02");
                r.Type    = PayReturnTypeEnum.Err;
                r.Content = "创建订单失败";
                return(r);
            }

            try
            {
                OnlinePay onlinepay = (OnlinePay)Activator.CreateInstance(Type.GetType(payPlatModel.Plat_class), payPlatModel, payMchModel);
                r = await onlinepay.Unifiedorder(orderid, paytype.ToString(), fee, ip, body, attach);
            }
            catch (Exception ex)
            {
                string err = ex.Message;
                Dos.Common.LogHelper.Debug("选用支付API接口失败:" + err);
                r.Type    = PayReturnTypeEnum.Err;
                r.Content = err;
                return(r);
            }

            if (r.Type != 0)
            {
                order.Plat_order_id = r.SerialNumber;
                order.Pay_amount    = decimal.Parse(r.RealPrice);
            }
            return(r);
        }
コード例 #11
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);
            }
        }
コード例 #12
0
        public IActionResult Edit(int id)
        {
            PayPlat model = PayPlatBll._.GetModelAsync(d => d.Plat_id == id).Result.data;

            return(View(model));
        }