public bool Insert(Model.Order.Bank.BankNotify model) { try { return(dal.Insert(model)); } catch (Exception exception) { ExceptionHandler.HandleException(exception); return(false); } }
/// <summary> /// </summary> /// <param name="model"></param> /// <returns></returns> public bool Insert(Model.Order.Bank.BankNotify model) { int rowsAffected = 0; SqlParameter[] parameters = { new SqlParameter("@orderid", SqlDbType.VarChar, 30), new SqlParameter("@status", SqlDbType.VarChar, 200), new SqlParameter("@message", SqlDbType.VarChar, 200), new SqlParameter("@httpStatusCode", SqlDbType.VarChar, 200), new SqlParameter("@StatusDescription", SqlDbType.VarChar, 2000), new SqlParameter("@againNotifyUrl", SqlDbType.VarChar, 2000), new SqlParameter("@notifycount", SqlDbType.Int, 4), new SqlParameter("@notifystat", SqlDbType.TinyInt, 1), new SqlParameter("@notifycontext", SqlDbType.VarChar, 200), new SqlParameter("@addtime", SqlDbType.DateTime), new SqlParameter("@notifytime", SqlDbType.DateTime) }; parameters[0].Value = model.orderid; parameters[1].Value = model.status; parameters[2].Value = model.message; parameters[3].Value = model.httpStatusCode; parameters[4].Value = model.StatusDescription; parameters[5].Value = model.againNotifyUrl; parameters[6].Value = model.notifycount; parameters[7].Value = model.notifystat; parameters[8].Value = model.notifycontext; parameters[9].Value = model.addtime; parameters[10].Value = model.notifytime; rowsAffected = DataBase.ExecuteNonQuery(CommandType.StoredProcedure, "proc_orderbank_notify", parameters); if (rowsAffected > 0) { return(true); } return(false); }
public int Timeout = 2 * 1000 * 60;//超时时间 public void Process(Object stateInfo) { var notifyInfo = (SysAutoReissueInfo)stateInfo; if (notifyInfo != null) { string notifyUrl = notifyInfo.NotifyUrl; string callbackText = string.Empty; string status = string.Empty; string message = string.Empty; string statusCode = string.Empty; string statusDesc = string.Empty; bool notifySucc = false; if (!string.IsNullOrEmpty(notifyUrl)) { #region 执行通知 try { callbackText = viviLib.Web.WebClientHelper.GetString(notifyUrl , string.Empty , "GET" , Encoding.GetEncoding(notifyInfo.InputCharset) , Timeout); if (!string.IsNullOrEmpty(callbackText)) { notifySucc = Utility.CheckCallBackIsSuccess(notifyInfo.InterfaceVersion, callbackText); } } catch (WebException e) { status = e.Status.ToString(); message = e.Message; if (e.Status == WebExceptionStatus.ProtocolError) { statusCode = ((HttpWebResponse)e.Response).StatusCode.ToString(); statusDesc = ((HttpWebResponse)e.Response).StatusDescription; } } catch (Exception e) { message = e.Message; } #endregion notifyInfo.NotifiedTimes++; int notifyStatus = notifySucc ? 2 : 4; if (notifyInfo.OrderType == 1) { #region 网银 var bankNotifyInfo = new Model.Order.Bank.BankNotify() { orderid = notifyInfo.OrderId, status = status, message = message, httpStatusCode = statusCode, StatusDescription = statusDesc, againNotifyUrl = notifyUrl, notifystat = notifyStatus, notifycontext = callbackText, notifytime = DateTime.Now }; BLL.Order.Bank.BankNotify.Instance.Insert(bankNotifyInfo); #endregion } else if (notifyInfo.OrderType == 2) { #region 点卡 var cardNotifyInfo = new Model.Order.Card.CardNotify() { orderid = notifyInfo.OrderId, status = status, message = message, httpStatusCode = statusCode, StatusDescription = statusDesc, againNotifyUrl = notifyUrl, notifystat = notifyStatus, notifycontext = callbackText, notifytime = DateTime.Now }; BLL.Order.Card.CardNotify.Instance.Insert(cardNotifyInfo); #endregion } else if (notifyInfo.OrderType == 4) { #region 多卡 var cardNotifyInfo = new Model.Order.Card.CardNotify() { orderid = notifyInfo.OrderId, status = status, message = message, httpStatusCode = statusCode, StatusDescription = statusDesc, againNotifyUrl = notifyUrl, notifystat = notifyStatus, notifycontext = callbackText, notifytime = DateTime.Now }; BLL.Order.Card.OrderCardTotal.Instance.Notify(notifyInfo.OrderId, notifyUrl, notifyStatus); #endregion } if (notifySucc || notifyInfo.NotifiedTimes >= 10) { if (notifyInfo.TimerReissue != null) { notifyInfo.TimerReissue.Dispose(); notifyInfo.TimerReissue = null; } } else { switch (notifyInfo.NotifiedTimes) { case 2: (notifyInfo.TimerReissue).Change(TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(200)); //10s break; case 3: (notifyInfo.TimerReissue).Change(TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(200)); //1分钟 break; case 4: (notifyInfo.TimerReissue).Change(TimeSpan.FromMinutes(10), TimeSpan.FromSeconds(200)); //10分钟 break; case 5: (notifyInfo.TimerReissue).Change(TimeSpan.FromMinutes(30), TimeSpan.FromSeconds(200)); //30分钟 break; default: (notifyInfo.TimerReissue).Change(TimeSpan.FromMinutes(30), TimeSpan.FromSeconds(200)); //30分钟 break; } } } } }
/// <summary> /// 同步补发 /// </summary> /// <param name="orderId">订单号</param> /// <returns></returns> public static string SynchronousNotify(string orderId) { if (string.IsNullOrEmpty(orderId)) { return(string.Empty); } var orderInfo = Factory.Instance.GetModelByOrderId(orderId); if (orderInfo == null) { return(string.Empty); } string successFlag = Successflag(orderInfo.version); string notifyUrl = GetBankBackUrl(orderInfo, true); string callback = string.Empty; string status = string.Empty; string message = string.Empty; string statusCode = string.Empty; string statusDesc = string.Empty; bool isOk = false; int notifystat = 4; try { if (viviLib.Text.PageValidate.IsUrl(notifyUrl)) { try { callback = viviLib.Web.WebClientHelper.GetString(notifyUrl , string.Empty , "GET" , Encoding.GetEncoding("GB2312") , 5 * 1000); isOk = callback.StartsWith(successFlag) || callback.ToLower().StartsWith(successFlag); if (isOk) { notifystat = 2; } } catch (WebException e) { message = e.Message; status = e.Status.ToString(); if (e.Status == WebExceptionStatus.ProtocolError) { statusCode = ((HttpWebResponse)e.Response).StatusCode.ToString(); statusDesc = ((HttpWebResponse)e.Response).StatusDescription; } } catch (Exception ex) { ExceptionHandler.HandleException(ex); } if (orderInfo.notifystat != 2) { var notify = new Model.Order.Bank.BankNotify() { orderid = orderInfo.orderid, status = status, message = message, httpStatusCode = statusCode, StatusDescription = statusDesc, againNotifyUrl = notifyUrl, notifystat = notifystat, notifycontext = callback, notifytime = DateTime.Now }; BLL.Order.Bank.BankNotify.Instance.Insert(notify); } } else { callback = "返回地址不正确!"; } } catch (Exception ex) { } return(callback); }
/// <summary> /// 将结果返回到数据库 /// </summary> /// <param name="oclass"></param> /// <param name="order"></param> /// <param name="notifyUrl"></param> /// <param name="times"></param> /// <param name="callbacktext"></param> /// <param name="success">是否执行成功</param> /// <param name="status"></param> /// <param name="message"></param> /// <param name="statusCode"></param> /// <param name="statusDesc"></param> private static void InsertToDb(byte oclass, object order, string notifyUrl, int times, string callbacktext, bool success, string status, string message, string statusCode, string statusDesc) { bool isnotifysucc = false; switch (oclass) { case 1: { #region 网银通知 var orderInfo = order as OrderBankInfo; if (orderInfo != null) { if (success && !string.IsNullOrEmpty(callbacktext)) { isnotifysucc = Utility.CheckCallBackIsSuccess(orderInfo.version, callbacktext); } var notify = new Model.Order.Bank.BankNotify() { orderid = orderInfo.orderid, status = status, message = message, httpStatusCode = statusCode, StatusDescription = statusDesc, againNotifyUrl = notifyUrl, notifystat = isnotifysucc ? 2 : 4, notifycontext = callbacktext, notifytime = DateTime.Now }; BLL.Order.Bank.BankNotify.Instance.Insert(notify); if (orderInfo.notifystat != 2) { viviLib.Logging.LogHelper.Write("orderInfo.notifystat fail=>" + orderInfo.orderid); //没有成功将发送到异常队列 多次通知 BanknotifyQueue.Send(orderInfo); #region 系统定时补发 //var sysAutoReissueNotifyInfo = new SysAutoReissueInfo //{ // OrderType = 1, // OrderId = orderInfo.orderid, // InterfaceVersion = orderInfo.version, // NotifyUrl = notifyUrl //}; //var reissue = new SysAutoReissue(); ////5s后重试 //var timerReissue = new System.Threading.Timer(reissue.Process, sysAutoReissueNotifyInfo, 5000, 0); //sysAutoReissueNotifyInfo.TimerReissue = timerReissue; #endregion } } #endregion } break; case 2: { #region 点卡 var orderInfo = order as OrderCardInfo; if (orderInfo != null) { if (success) { isnotifysucc = Card.Utility.CheckCallBackIsSuccess(orderInfo.version, callbacktext); } var notify = new Model.Order.Card.CardNotify() { orderid = orderInfo.orderid, status = status, message = message, httpStatusCode = statusCode, StatusDescription = statusDesc, againNotifyUrl = notifyUrl, notifystat = isnotifysucc ? 2 : 4, notifycontext = callbacktext, notifytime = DateTime.Now, InterVersion = orderInfo.version }; BLL.Order.Card.CardNotify.Instance.Insert(notify); if (orderInfo.notifystat != 2) { //没有成功将发送到异常队列 多次通知 // CardnotifyQueue.Send(orderInfo); CardnotifyQueueX.Send(notify); #region 系统定时补发 //var sysAutoReissueNotifyInfo = new SysAutoReissueInfo //{ // OrderType = 2, // OrderId = orderInfo.orderid, // InterfaceVersion = orderInfo.version, // NotifyUrl = notifyUrl //}; //var reissue = new SysAutoReissue(); ////5s后重试 //var timerReissue = new System.Threading.Timer(reissue.Process, sysAutoReissueNotifyInfo, 5000, 0); //sysAutoReissueNotifyInfo.TimerReissue = timerReissue; #endregion } } #endregion } break; case 4: { #region 点卡 var orderInfo = order as OrderCardTotal; if (orderInfo != null) { int notifyStatus = 4; if (success) { isnotifysucc = Card.Utility.CheckCallBackIsSuccess(orderInfo.version, callbacktext); if (isnotifysucc) { notifyStatus = 2; } } var notify = new CardNotify() { orderid = orderInfo.orderid, status = status, message = message, httpStatusCode = statusCode, StatusDescription = statusDesc, againNotifyUrl = notifyUrl, notifystat = isnotifysucc ? 2 : 4, notifycontext = callbacktext, notifytime = DateTime.Now, InterVersion = orderInfo.version }; BLL.Order.Card.OrderCardTotal.Instance.Notify(orderInfo.orderid, notifyUrl, notifyStatus); if (isnotifysucc == false) { CardnotifyQueueX.Send(notify); //#region 系统定时补发 //var sysAutoReissueNotifyInfo = new SysAutoReissueInfo //{ // OrderType = 4, // OrderId = orderInfo.orderid, // InterfaceVersion = orderInfo.version, // NotifyUrl = notifyUrl //}; //var reissue = new SysAutoReissue(); ////5s后重试 //var timerReissue = new System.Threading.Timer(reissue.Process, sysAutoReissueNotifyInfo, 5000, 0); //sysAutoReissueNotifyInfo.TimerReissue = timerReissue; //#endregion } //BLL.Order.Card.CardNotify.Instance.Insert(notify); //if (orderInfo.notifystat != 2) //{ // //没有成功将发送到异常队列 多次通知 // //CardnotifyQueue.Send(orderInfo); //} } #endregion } break; } }
/// <summary> /// /// </summary> /// <param name="info"></param> private void Process(OrderNotify info) { try { string notifyUrl = info.NotifyUrl; if (string.IsNullOrEmpty(notifyUrl)) { return; } string callback = string.Empty; string status = string.Empty; string message = string.Empty; string statusCode = string.Empty; string statusDesc = string.Empty; bool isOk = false; try { callback = viviLib.Web.WebClientHelper.GetString(notifyUrl , string.Empty , "GET" , Encoding.GetEncoding("GB2312") , 1 * 60 * 1000); isOk = Utility.CheckCallBackIsSuccess(info.OrderInfo.version, callback); } catch (WebException e) { message = e.Message; status = e.Status.ToString(); if (e.Status == WebExceptionStatus.ProtocolError) { statusCode = ((HttpWebResponse)e.Response).StatusCode.ToString(); statusDesc = ((HttpWebResponse)e.Response).StatusDescription; } } catch (Exception e) { message = e.Message; } int notifystat = isOk ? 2 : 4; var notifyInfo = new Model.Order.Bank.BankNotify() { orderid = info.OrderInfo.orderid, status = status, message = message, httpStatusCode = statusCode, StatusDescription = statusDesc, againNotifyUrl = notifyUrl, notifystat = notifystat, notifycontext = callback, notifytime = DateTime.Now }; BankNotify.Instance.Insert(notifyInfo); if (isOk) { if (info.Tmr != null) { info.Tmr.Dispose(); info.Tmr = null; } } } catch (Exception exception) { ExceptionHandler.HandleException(exception); } }
/// <summary> /// /// </summary> /// <param name="version"></param> /// <param name="orderid"></param> /// <param name="notifyUrl"></param> /// <returns></returns> public static bool Process(string version, string orderid, string notifyUrl) { try { string callback = string.Empty; string status = string.Empty; string message = string.Empty; string statusCode = string.Empty; string statusDesc = string.Empty; bool isOk = false; int notifystat = 4; if (viviLib.Text.PageValidate.IsUrl(notifyUrl)) { try { callback = viviLib.Web.WebClientHelper.GetString(notifyUrl , string.Empty , "GET" , Encoding.GetEncoding("GB2312") , 60 * 1000); isOk = Utility.CheckCallBackIsSuccess(version, callback); if (isOk) { notifystat = 2; } } catch (WebException e) { message = e.Message; status = e.Status.ToString(); if (e.Status == WebExceptionStatus.ProtocolError) { statusCode = ((HttpWebResponse)e.Response).StatusCode.ToString(); statusDesc = ((HttpWebResponse)e.Response).StatusDescription; } ExceptionHandler.HandleException(e); } catch (Exception ex) { ExceptionHandler.HandleException(ex); } var notify = new Model.Order.Bank.BankNotify() { orderid = orderid, status = status, message = message, httpStatusCode = statusCode, StatusDescription = statusDesc, againNotifyUrl = notifyUrl, notifystat = notifystat, notifycontext = callback, notifytime = DateTime.Now }; BankNotify.Instance.Insert(notify); return(isOk); } else { callback = "返回地址不正确!"; } return(false); } catch (Exception exception) { ExceptionHandler.HandleException(exception); return(false); } }