Esempio n. 1
0
        const int DefaultTimeout = 2 * 60 * 1000; // 2 minutes timeout

        #region UpdatetoDB
        /// <summary>
        /// 将结果返回到数据库
        /// </summary>
        /// <param name="oclass"></param>
        /// <param name="obj"></param>
        /// <param name="agurl"></param>
        /// <param name="times"></param>
        /// <param name="callbacktext"></param>
        private static void UpdatetoDB(int oclass, object obj, string agurl, int times, string callbacktext, bool success, string errcode)
        {
            if (oclass == 1)
            {
                OrderBankInfo orderInfo = obj as OrderBankInfo;
                if (orderInfo != null)
                {
                    OrderBank dal = new OrderBank();

                    //string SuccessFlag = SystemApiHelper.Successflag(orderInfo.version);

                    bool isnotifysucc = SystemApiHelper.CheckCallBackIsSuccess(orderInfo.version, callbacktext);

                    orderInfo.notifystat     = isnotifysucc ? 2 : 4;
                    orderInfo.againNotifyUrl = agurl;
                    orderInfo.notifycontext  = callbacktext;
                    orderInfo.notifycount    = times;
                    orderInfo.notifytime     = DateTime.Now;
                    dal.UpdateNotifyInfo(orderInfo);

                    if (orderInfo.notifystat != 2)
                    {
                        //没有成功将发送到异常队列 多次通知
                        banknotifyQueue.Send(orderInfo);
                    }
                }
            }
            else if (oclass == 2)
            {
                OrderCardInfo orderInfo = obj as OrderCardInfo;
                if (orderInfo != null)
                {
                    OrderCard dal = new OrderCard();

                    bool isnotifysucc = SystemApiHelper.CheckCallBackIsSuccess(orderInfo.version, callbacktext);
                    orderInfo.notifystat     = isnotifysucc ? 2 : 4;
                    orderInfo.againNotifyUrl = agurl;
                    orderInfo.notifycontext  = callbacktext;
                    orderInfo.notifycount    = times;
                    orderInfo.notifytime     = DateTime.Now;

                    dal.UpdateNotifyInfo(orderInfo);

                    if (orderInfo.notifystat != 2)
                    {
                        //没有成功将发送到异常队列 多次通知
                        cardnotifyQueue.Send(orderInfo);
                    }
                }
            }
            else if (oclass == 3)
            {
                OrderSmsInfo orderInfo = obj as OrderSmsInfo;

                if (orderInfo != null)
                {
                    OrderSms dal = new OrderSms();

                    orderInfo.notifystat     = success ? 2:4;
                    orderInfo.issucc         = success;
                    orderInfo.errcode        = errcode;
                    orderInfo.againNotifyUrl = agurl;
                    orderInfo.notifycontext  = callbacktext;
                    orderInfo.notifycount    = times;
                    dal.UpdateNotifyInfo(orderInfo);

                    if (orderInfo.notifystat != 2)
                    {
                        //没有成功将发送到异常队列 多次通知
                        smsnotifyQueue.Send(orderInfo);
                    }
                }
            }
        }
Esempio n. 2
0
        //#region SynchronousNotify
        ///// <summary>
        ///// 同步补发
        ///// </summary>
        ///// <param name="orderId"></param>
        ///// <returns></returns>
        //public string SynchronousNotify(string orderId)
        //{
        //    if (string.IsNullOrEmpty(orderId))
        //        return string.Empty;

        //    //OrderBank _orderBank = new OrderBank();
        //    OrderBankInfo orderInfo = BLL.Order.Bank.Factory.Instance.GetModelByOrderId(orderId);
        //    if (orderInfo == null)
        //        return string.Empty;

        //    string SuccessFlag = SystemApiHelper.Successflag(orderInfo.version);
        //    string notifyUrl = _orderBank.GetCallBackUrl(orderInfo);
        //    string callback = string.Empty;
        //    try
        //    {
        //        if (viviLib.Text.PageValidate.IsUrl(notifyUrl))
        //        {
        //            callback = viviLib.Web.WebClientHelper.GetString(notifyUrl
        //                , string.Empty
        //                , "GET"
        //                , System.Text.Encoding.GetEncoding("GB2312")
        //                , 100000);

        //            bool isOk = callback.StartsWith(SuccessFlag) || callback.ToLower().StartsWith(SuccessFlag);

        //            if (isOk && orderInfo.notifystat != 2)
        //            {
        //                orderInfo.notifystat = 2;
        //                orderInfo.againNotifyUrl = notifyUrl;
        //                orderInfo.notifycontext = callback;
        //                _orderBank.UpdateNotifyInfo(orderInfo);
        //            }
        //        }
        //        else
        //        {
        //            callback = "返回地址不正确!";
        //        }
        //    }
        //    catch { }

        //    return callback;
        //}
        //#endregion

        #region NotifyCheckStatus
        /// <summary>
        ///
        /// </summary>
        /// <param name="stateInfo"></param>
        public void NotifyCheckStatus(Object stateInfo)
        {
            try
            {
                OrderBank _orderBank = new OrderBank();

                viviapi.Model.Order.OrderNotify _notify = (viviapi.Model.Order.OrderNotify)stateInfo;
                string notifyUrl = ""; //_orderBank.GetCallBackUrl(_notify.orderInfo);

                string SuccessFlag = SystemApiHelper.Successflag(_notify.orderInfo.version);

                if (string.IsNullOrEmpty(notifyUrl))
                {
                    _notify.tmr.Dispose();
                    _notify.tmr = null;
                }
                else
                {
                    bool timerflag = false;
                    _notify.orderInfo.notifycount++;

                    if (_notify.tmr != null)
                    {
                        switch (_notify.orderInfo.notifycount)
                        {
                        case 1:
                            timerflag = (_notify.tmr).Change(TimeSpan.FromSeconds(20), TimeSpan.FromSeconds(200));
                            break;

                        case 2:
                            timerflag = (_notify.tmr).Change(TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(200));    //1分钟
                            break;

                        case 3:
                            timerflag = (_notify.tmr).Change(TimeSpan.FromMinutes(2), TimeSpan.FromSeconds(200));    //2分钟
                            break;

                        case 4:
                            timerflag = (_notify.tmr).Change(TimeSpan.FromMinutes(5), TimeSpan.FromSeconds(200));    //5分钟
                            break;

                        case 5:
                            timerflag = (_notify.tmr).Change(TimeSpan.FromMinutes(10), TimeSpan.FromSeconds(200));    //10分钟
                            break;

                        case 6:
                            timerflag = (_notify.tmr).Change(TimeSpan.FromMinutes(20), TimeSpan.FromSeconds(200));    //20分钟
                            break;

                        case 7:
                            timerflag = (_notify.tmr).Change(TimeSpan.FromMinutes(30), TimeSpan.FromSeconds(200));    //30分钟
                            break;

                        case 8:
                            timerflag = (_notify.tmr).Change(TimeSpan.FromMinutes(60), TimeSpan.FromSeconds(200));    //1小时
                            break;

                        case 9:
                            timerflag = (_notify.tmr).Change(TimeSpan.FromMinutes(120), TimeSpan.FromSeconds(200));    //2小时
                            break;

                        case 10:
                            timerflag = (_notify.tmr).Change(TimeSpan.FromMinutes(240), TimeSpan.FromSeconds(200));    //4小时
                            break;
                        }
                    }

                    string callback = string.Empty;

                    try { callback = viviLib.Web.WebClientHelper.GetString(notifyUrl, string.Empty, "GET", System.Text.Encoding.GetEncoding("GB2312"), 100000); }
                    catch (WebException e) { callback = e.Status.ToString() + e.Message; }

                    if (_notify.orderInfo.notifycount <= 10)// || callback.ToLower() == SuccessFlag)//
                    {
                        bool isOk = callback.StartsWith(SuccessFlag) || callback.ToLower().StartsWith(SuccessFlag);
                        _notify.orderInfo.notifystat     = isOk ? 2 : 4;
                        _notify.orderInfo.againNotifyUrl = notifyUrl;
                        _notify.orderInfo.notifycontext  = callback;
                        _notify.orderInfo.notifytime     = DateTime.Now;
                        _orderBank.UpdateNotifyInfo(_notify.orderInfo);
                    }

                    if (callback.ToLower() == SuccessFlag || _notify.orderInfo.notifycount >= 10)
                    {
                        if (_notify.tmr != null)
                        {
                            _notify.tmr.Dispose();
                            _notify.tmr = null;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                viviLib.ExceptionHandling.ExceptionHandler.HandleException(ex);
            }
        }