public async Task <QueryReturnModel> Query(string mchid, string orderid, string sign) { QueryReturnModel r = new QueryReturnModel(); SortedDictionary <string, string> para = new SortedDictionary <string, string>(); para.Add("mchid", mchid); para.Add("orderid", orderid); string temp = string.Format("{0}&key={1}", OnlinePay.GetParamSrc(para), WebConfig.MchKey); Dos.Common.LogHelper.Debug(temp); if (mchid != WebConfig.MchId) { Dos.Common.LogHelper.Debug(" Query 商户号不存在"); r.ReturnMsg = "商户号不存在"; return(r); } string cusSign = Dos.Common.EncryptHelper.MD5EncryptWeChat(temp, "utf-8"); if (cusSign.ToLower() != sign.ToLower()) { Dos.Common.LogHelper.Debug(" Query 签名错误"); r.ReturnMsg = "签名错误"; return(r); } return(await PayOrderBll._.Query(mchid, orderid)); }
public async Task <QueryReturn> Query(string mchid, string orderid, string sign) { QueryReturn r = new QueryReturn(); SortedDictionary <string, string> para = new SortedDictionary <string, string>(); para.Add("mchid", mchid); para.Add("orderid", orderid); string temp = string.Format("{0}&key={1}", OnlinePay.GetParamSrc(para), DB.MchKey); Dos.Common.LogHelper.Debug(temp); if (mchid != DB.MchId) { r.ReturnMsg = "商户号不存在"; return(r); } temp = Dos.Common.EncryptHelper.MD5EncryptWeChat(temp, "utf-8"); if (temp != sign) { r.ReturnMsg = "签名错误"; return(r); } return(await Pay_OrderBll.Instance.Query(mchid, orderid)); }
/// <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); }
public async Task <UnifiedorderReturn> Unifiedorder(string mchid, string orderid, string body, int paytype, string amount, string attach, string ip, string callbackurl, string notifyurl, string sign) { SortedDictionary <string, string> para = new SortedDictionary <string, string>(); para.Add("mchid", mchid); para.Add("orderid", orderid); para.Add("body", body); para.Add("paytype", paytype.ToString()); para.Add("amount", amount); para.Add("attach", attach); para.Add("ip", ip); para.Add("callbackurl", callbackurl); para.Add("notifyurl", notifyurl); string temp = string.Format("{0}&key={1}", OnlinePay.GetParamSrc(para), DB.MchKey); Dos.Common.LogHelper.Debug(temp); UnifiedorderReturn r = new UnifiedorderReturn(); if (mchid != DB.MchId) { r.Type = PayReturnType.Err; r.Content = "商户号不存在"; return(r); } temp = Dos.Common.EncryptHelper.MD5EncryptWeChat(temp, "utf-8"); if (temp != sign) { r.Type = PayReturnType.Err; r.Content = "签名错误"; return(r); } return(await Pay_OrderBll.Instance.Unifiedorder(mchid, orderid, body, paytype, amount, attach, ip, callbackurl, notifyurl)); }
public async Task <UnifiedOrderReturnModel> Unifiedorder([FromForm] PayOrderModel payOrder) { //string mchid, string orderid, string body, int paytype, string amount, string attach, string ip, string callbackurl, string notifyurl, string sign SortedDictionary <string, string> para = new SortedDictionary <string, string>(); para.Add("mchid", payOrder.MchId); para.Add("orderid", payOrder.OrderId); para.Add("body", payOrder.Body); para.Add("paytype", payOrder.PayType.ToString()); para.Add("amount", payOrder.Amount); para.Add("attach", payOrder.Attach); para.Add("ip", payOrder.Ip); para.Add("callbackurl", payOrder.CallBackUrl); para.Add("notifyurl", payOrder.NotifyUrl); string temp = string.Format("{0}&key={1}", OnlinePay.GetParamSrc(para), WebConfig.MchKey); Dos.Common.LogHelper.Debug(temp); UnifiedOrderReturnModel r = new UnifiedOrderReturnModel(); if (payOrder.MchId != WebConfig.MchId) { Dos.Common.LogHelper.Debug("商户号不存在"); r.Type = PayReturnTypeEnum.Err; r.Content = "商户号不存在"; return(r); } string cusSign = Dos.Common.EncryptHelper.MD5EncryptWeChat(temp, "utf-8"); if (cusSign.ToLower() != payOrder.Sign.ToLower()) { Dos.Common.LogHelper.Debug("签名错误"); r.Type = PayReturnTypeEnum.Err; r.Content = "签名错误"; return(r); } return(await PayOrderBll._.Unifiedorder(payOrder.MchId, payOrder.OrderId, payOrder.Body, payOrder.PayType, payOrder.Amount, payOrder.Attach, payOrder.Ip, payOrder.CallBackUrl, payOrder.NotifyUrl)); }
public async Task <string> SendNotify(string orderid) { Pay_order o = DB.Context.From <Pay_order>().Where(p => p.Order_id == orderid).First(); if (o == null || o.Order_id != orderid) { return("订单不存在"); } if (o.Notify_url.Length < 7) { return("订单通知地址不误"); } SortedDictionary <string, string> para = new SortedDictionary <string, string>(); para.Add("mchid", DB.MchId); para.Add("orderid", o.Order_id); para.Add("serialid", o.Plat_order_id); para.Add("amount", o.Pay_amount.ToString()); para.Add("attach", o.Attach); para.Add("status", o.Status.ToString()); string sign = string.Format("{0}&key={1}", OnlinePay.GetParamSrc(para), DB.MchKey); sign = Dos.Common.EncryptHelper.MD5EncryptWeChat(sign, "utf-8"); para.Add("sign", sign); string msg = Task.Run(() => { string r; try { r = Dos.Common.HttpHelper.Post( new Dos.Common.HttpParam { Url = o.Notify_url, Encoding = System.Text.Encoding.UTF8, ParamType = Dos.Common.EnumHelper.HttpParamType.Form, GetParam = para } ); } catch (Exception ee) { r = ee.ToString(); } return(r); }).Result; if (o.Notify_status < 2) { if (msg == "ok") { o.Notify_status = 2; } else { o.Notify_status = 1; } if (o.Notify_times == null) { o.Notify_times = 0; } o.Notify_times = o.Notify_times + 1; o.Notify_lasttime = DateTime.Now.ToTimeStamp(); if (o.Notify_status != 2) { switch (o.Notify_times) { case 1: Publish(DB.MchId, o.Order_id, 60); break; //1分钟后再次通知 case 2: Publish(DB.MchId, o.Order_id, 300); break; //5分钟后再次通知 case 3: Publish(DB.MchId, o.Order_id, 900); break; //15分钟后再次通知 case 4: Publish(DB.MchId, o.Order_id, 7200); break; //2小时后再次通知 case 5: Publish(DB.MchId, o.Order_id, 21600); break; //6小时后再次通知 default: break; } } DB.Context.Save(o); } return(msg); }
/// <summary> /// 发送通知 /// </summary> /// <param name="orderid"></param> /// <param name="isSystem"></param> /// <returns></returns> public async Task <string> SendNotify(string orderid, bool isSystem = true, bool isAsyn = true) { PayOrder o = DbContext._.Db.From <PayOrder>().Where(p => p.Order_id == orderid).First(); if (o == null || o.Order_id != orderid) { return("订单不存在"); } if (o.Status != 1) { return("订单状态还未成功"); } if (o.Notify_status == 1) { return("订单异步通知已成功"); } if (o.Notify_url.Length < 7) { return("订单通知地址不误"); } //AopDictionary para = new AopDictionary(); SortedDictionary <string, string> para = new SortedDictionary <string, string>(); para.Add("mchid", WebConfig.MchId); para.Add("orderid", o.Order_id); para.Add("serialid", o.Plat_order_id); para.Add("amount", o.Pay_amount.ToString()); para.Add("attach", o.Attach); para.Add("status", o.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); string msg = "异步通知发送中..."; if (isAsyn) { msg = Task.Run(() => { string r; try { r = WebUtils.Post(o.Notify_url, WebUtils.BuildQuery(para, "utf-8")); } catch (Exception ee) { r = ee.ToString(); } if (o.Notify_status != 1) { o.Attach(EntityState.Modified); if (r == "ok") { o.Notify_status = 1; } else { o.Notify_status = 2; } if (o.Notify_times == null) { o.Notify_times = 0; } o.Notify_times = o.Notify_times + 1; o.Notify_lasttime = DateTime.Now.ToTimeStamp(); if (isSystem) { if (o.Notify_status != 1) { switch (o.Notify_times) { case 1: Publish(WebConfig.MchId, o.Order_id, 60); break; //1分钟后再次通知 case 2: Publish(WebConfig.MchId, o.Order_id, 300); break; //5分钟后再次通知 case 3: Publish(WebConfig.MchId, o.Order_id, 900); break; //15分钟后再次通知 case 4: Publish(WebConfig.MchId, o.Order_id, 7200); break; //2小时后再次通知 case 5: Publish(WebConfig.MchId, o.Order_id, 21600); break; //6小时后再次通知 default: break; } } } DbContext._.Db.Save(o); } return(r); }).Result; return(msg); } else { string r; try { r = WebUtils.Post(o.Notify_url, WebUtils.BuildQuery(para, "utf-8")); } catch (Exception ee) { r = ee.ToString(); } if (o.Notify_status != 1) { o.Attach(EntityState.Modified); if (r == "ok") { o.Notify_status = 1; } else { o.Notify_status = 2; } if (o.Notify_times == null) { o.Notify_times = 0; } o.Notify_times = o.Notify_times + 1; o.Notify_lasttime = DateTime.Now.ToTimeStamp(); if (isSystem) { if (o.Notify_status != 1) { switch (o.Notify_times) { case 1: Publish(WebConfig.MchId, o.Order_id, 60); break; //1分钟后再次通知 case 2: Publish(WebConfig.MchId, o.Order_id, 300); break; //5分钟后再次通知 case 3: Publish(WebConfig.MchId, o.Order_id, 900); break; //15分钟后再次通知 case 4: Publish(WebConfig.MchId, o.Order_id, 7200); break; //2小时后再次通知 case 5: Publish(WebConfig.MchId, o.Order_id, 21600); break; //6小时后再次通知 default: break; } } } DbContext._.Db.Save(o); } return(r); } #region //if (o.Notify_status != 1) //{ // o.Attach(EntityState.Modified); // if (msg == "ok") // { // o.Notify_status = 1; // } // else // { // o.Notify_status = 2; // } // if (o.Notify_times == null) { o.Notify_times = 0; } // o.Notify_times = o.Notify_times + 1; // o.Notify_lasttime = DateTime.Now.ToTimeStamp(); // if (isSystem) // { // if (o.Notify_status != 1) // { // switch (o.Notify_times) // { // case 1: Publish(WebConfig.MchId, o.Order_id, 60); break; //1分钟后再次通知 // case 2: Publish(WebConfig.MchId, o.Order_id, 300); break; //5分钟后再次通知 // case 3: Publish(WebConfig.MchId, o.Order_id, 900); break; //15分钟后再次通知 // case 4: Publish(WebConfig.MchId, o.Order_id, 7200); break; //2小时后再次通知 // case 5: Publish(WebConfig.MchId, o.Order_id, 21600); break; //6小时后再次通知 // default: break; // } // } // } // DbContext._.Db.Save(o); //} #endregion }