Пример #1
0
        /// <summary>
        /// 根据监控器接口实现检测通道状态
        /// </summary>
        /// <param name="payChannelMonitor">通道监控器接口实现</param>
        /// <returns></returns>
        private bool CheckPayChannel(IPayChannelMonitor payChannelMonitor)
        {
            //检测2次
            var  maxRetries = 2;
            bool success;

            do
            {
                try
                {
                    if (payChannelMonitor.AllowAutoCheck == true && payChannelMonitor is ZhiFuBaoPayChannelMonitor)
                    {
                        success = payChannelMonitor.checkorder();
                    }
                    else
                    {
                        success = payChannelMonitor.Check();
                    }
                    if (success)
                    {
                        break;
                    }
                    maxRetries--;
                    Thread.Sleep(500);
                }
                catch (Exception ex)
                {
                    success = false;
                    AddLocLog.AddLog(1, 4, Request.UserHostAddress, "通道状态检测", ex.ToString());
                    break;
                }
            } while (maxRetries > 0);
            return(success);
        }
Пример #2
0
        /// <summary>
        /// 支付通道检测器,传入通道类型,工厂自动生成对应的接口实现
        /// </summary>
        /// <param name="payType">通道类型,1:支付宝,2:微信</param>
        /// <returns></returns>
        public static IPayChannelMonitor Creator(int payType)
        {
            IPayChannelMonitor payChannelMonitor = null;

            switch (payType)
            {
            //支付宝通道
            case 1:
                payChannelMonitor = new ZhiFuBaoPayChannelMonitor();
                break;

            //微信通道
            case 2:
                payChannelMonitor = new WeiXinPayChannelMonitor();
                break;
            }
            return(payChannelMonitor);
        }