public OnlineSettle(SettlePlat p, SettleMch m) { if (p == null) { return; } if (m == null) { return; } this.Plat = new SettlePlat(); this.Plat.Plat_id = p.Plat_id; this.Plat.Plat_name = p.Plat_name; this.Plat.Pay_gateway = p.Pay_gateway; this.Plat.Banklist = p.Banklist; 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; //this = (OnlinePay)Activator.CreateInstance(Type.GetType(this.Plat.Class)); }
public OnlineSettle(int plat, string mchid) { SettlePlat p = PlatList.Find(pp => pp.Plat_id == plat); if (p == null || p.Plat_id != plat) { return; } SettleMch 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 SettlePlat(); this.Plat.Plat_id = p.Plat_id; this.Plat.Plat_name = p.Plat_name; this.Plat.Pay_gateway = p.Pay_gateway; this.Plat.Banklist = p.Banklist; 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; }
public async Task <ApiResult <string> > Add(SettlePlat parm) { parm.Plat_name = parm.Plat_name ?? ""; parm.Plat_class = parm.Plat_class ?? ""; parm.Req_gateway = parm.Req_gateway ?? ""; parm.Pay_gateway = parm.Pay_gateway ?? ""; return(await SettlePlatBll._.AddAsync(parm)); }
/// <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); }
/// <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); } }
public async Task <ApiResult <string> > ModifyPayMch(SettlePlat parm) { Dictionary <Field, object> model = new Dictionary <Field, object>(); model.Add(SettlePlat._.Plat_name, parm.Plat_name.SqlFilters() ?? ""); model.Add(SettlePlat._.Plat_class, parm.Plat_class.SqlFilters() ?? ""); model.Add(SettlePlat._.Req_gateway, parm.Req_gateway.SqlFilters() ?? ""); model.Add(SettlePlat._.Pay_gateway, parm.Pay_gateway.SqlFilters() ?? ""); model.Add(SettlePlat._.Banklist, parm.Banklist.SqlFilters() ?? ""); model.Add(SettlePlat._.Min_money, parm.Min_money); model.Add(SettlePlat._.Max_money, parm.Max_money); return(await SettlePlatBll._.UpdateAsync(model, d => d.Plat_id == parm.Plat_id)); }
/// <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 appid, 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) { UnifiedOrderReturnModel r = new UnifiedOrderReturnModel(); if (appid != WebConfig.MchId) { r.Type = PayReturnTypeEnum.Err; r.Content = "约定的appid错误"; return(r); } decimal fee = 0; decimal.TryParse(amount, out fee); if (fee <= 0) { r.Type = PayReturnTypeEnum.Err; r.Content = "打款金额必须大于0"; return(r); } //SettleMch 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()).FirstOrDefault(); SettleMch m = OnlineSettle.MchList.FindAll(pp => pp.Id == Convert.ToInt32(mchid) && pp.Nullity == false && ("," + pp.BankList + ",").Contains("," + Bank_name.Trim() + ",") && (pp.Max_money >= fee) && (pp.Min_money <= fee)).OrderBy(i => Guid.NewGuid()).FirstOrDefault(); if (m == null) { r.Type = PayReturnTypeEnum.Err; r.Content = "平台没有可用的打款渠道"; return(r); } SettlePlat p = OnlineSettle.GetPlat(m.Plat_id); if (p == null) { r.Type = PayReturnTypeEnum.Err; r.Content = "平台支付渠道有误"; return(r); } if (DbContext._.Db.Exists <SettleOrder>(o => o.Order_id == orderid)) { r.Type = PayReturnTypeEnum.Err; r.Content = "订单号已经存在"; return(r); } SettleOrder order = new SettleOrder(); order.Order_id = orderid; order.Plat_order_id = ""; 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; bool isSuccess = false; try { isSuccess = DbContext._.Db.Insert <SettleOrder>(order) > 0; } catch (Exception e) { string err = e.Message; throw; } 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; } return(r); }
/// <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); } }
public TestRealSettle(SettlePlat p, SettleMch m) : base(p, m) { }
public IActionResult Edit(int id) { SettlePlat model = SettlePlatBll._.GetModelAsync(d => d.Plat_id == id).Result.data; return(View(model)); }