Пример #1
0
        public async Task ProcessQueueAsync(ISmsProcessor processor)
        {
            var queue = await TextMessageQueue.GetMailInQueueAsync(this.Database).ConfigureAwait(false);

            var config = new SmsConfig(this.Database, this.Processor);

            this.Processor = processor;

            if (this.IsEnabled())
            {
                foreach (var mail in queue)
                {
                    var message = SmsHelper.GetMessage(config, mail);

                    await processor.SendAsync(message).ConfigureAwait(false);

                    if (message.Status == Status.Completed)
                    {
                        mail.Delivered   = true;
                        mail.DeliveredOn = DateTimeOffset.UtcNow;

                        await TextMessageQueue.SetSuccessAsync(this.Database, mail.QueueId).ConfigureAwait(false);
                    }
                }
            }
        }
        public SmsServices(IDataProvider dataProvider, IOptions <SmsConfig> options)
        {
            _dataProvider = dataProvider;
            _config       = options.Value;

            TwilioClient.Init(_config.AccountSid, _config.AuthToken);
        }
Пример #3
0
        public async Task AddAsync()
        {
            this.Processor = SmsProcessor.GetDefault(this.Database);

            if (!this.IsEnabled())
            {
                return;
            }

            var config = new SmsConfig(this.Database, this.Processor);


            if (string.IsNullOrWhiteSpace(this.Sms.FromName))
            {
                this.Sms.FromName = config.FromName;
            }

            if (string.IsNullOrWhiteSpace(this.Sms.FromNumber))
            {
                this.Sms.FromNumber = config.FromNumber;
            }

            var sysConfig = MessagingConfig.Get(this.Database);

            if (sysConfig.TestMode)
            {
                this.Sms.IsTest = true;
            }

            await TextMessageQueue.AddToQueueAsync(this.Database, this.Sms).ConfigureAwait(false);
        }
Пример #4
0
        public bool SendSms(Sms sms)
        {
            SmsConfig config = GetConfig();

            if (config != null)
            {
                //"[email protected]:project", "novohealth123"
                SmsProxy      smsengine = new SmsProxy(config.UserName, config.Password);
                List <string> tonumber  = new List <string>();
                tonumber.Add(sms.Msisdn);
                sms.Status = SmsStatus.Pending;
                SmsEngine.ServiceReference1.ResponseInfo resp = SmsProxy.SendSms(sms.FromId, tonumber, sms.Message, Convert.ToDateTime(sms.DeliveryDate));

                sms.ServerCode = resp.ErrorCode.ToString();

                if (resp.ErrorCode.Equals(0))
                {
                    sms.ServerResponse = resp.ExtraMessage;
                    sms.Status         = SmsStatus.Delivered;
                }
                else
                {
                    sms.ServerResponse = resp.ErrorMessage;
                }

                Savemessage(sms);
                return(true);
            }
            return(false);
        }
Пример #5
0
        public async Task <int> Update(SmsConfig smsConfig)
        {
            try
            {
                var spName          = "dbo.usp_SmsConfig_Update";
                var parameterValues = new object[7]
                {
                    smsConfig.Id,
                    smsConfig.AlertConfigId,
                    smsConfig.AccountName,
                    smsConfig.Mobile,
                    smsConfig.Message,
                    smsConfig.ServiceId,
                    smsConfig.DataSign
                };

                var thisTask = Task.Run(() => SqlHelper.ExecuteNonQueryAsync(_connString, spName, parameterValues));
                var result   = await thisTask;
                return(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #6
0
 public AuthMessageSender(IOptions <EmailConfig> emailConfig,
                          IOptions <SmsConfig> smsConfig,
                          ILoggerFactory loggerFactory)
 {
     _logger      = loggerFactory.CreateLogger <AuthMessageSender>();
     _smsConfig   = smsConfig.Value;
     _emailConfig = emailConfig.Value;
 }
Пример #7
0
        public GlobalSmsSender(SmsConfig smsConfig)
        {
            this.httpClient  = new HttpClient();
            this.smsConfig   = smsConfig ?? throw new ArgumentNullException(nameof(smsConfig));
            this.smsEndPoint = new Uri(smsConfig.EndPoint);

            httpClient.BaseAddress = new Uri($"{smsEndPoint.Scheme}://{smsEndPoint.Host}");
        }
Пример #8
0
            public ISmsSender Create()
            {
                // 短信发送者创建,从配置管理中读取当前的发送方式,并创建实例
                SmsConfig smsConfig = _configProvider.GetSmsConfig();
                // 通过工厂方法的方式,将如何创建具体短信发送者的逻辑从这里移走,实现了这个方法本身的稳定。
                ISmsSenderFactoryHandler factoryHandler = _smsSenderFactoryHandlers[smsConfig.SmsSenderType];
                ISmsSender smsSender = factoryHandler.Create();

                return(smsSender);
            }
Пример #9
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="smsLogRepository"></param>
 /// <param name="config"></param>
 /// <param name="httpFactory"></param>
 /// <param name="logger"></param>
 public SmsService(IRepositoryByInt <SmsLog> smsLogRepository,
                   IOptions <SmsConfig> config,
                   IHttpClientFactory httpFactory,
                   ILogger <SmsService> logger)
 {
     _smsLogRepository = smsLogRepository;
     _config           = config.Value;
     _httpFactory      = httpFactory;
     _logger           = logger;
 }
Пример #10
0
        public Task SendAsync(SmsConfig smsConfig)
        {
            TwilioClient.Init(SmsConfiguration.AccountSid, SmsConfiguration.AuthToken);
            var message = MessageResource.Create(
                body: smsConfig.Body,
                from: new Twilio.Types.PhoneNumber(smsConfig.From),
                to: new Twilio.Types.PhoneNumber(smsConfig.To)
                );

            return(Task.CompletedTask);
        }
        private void GetSettings()
        {
            SmsConfig = new SmsConfig();

            var config = settingsRepository.GetSettings();

            if (config != null)
            {
                SmsConfig = config.Clone() as SmsConfig;
            }
        }
Пример #12
0
        public bool UpdateSmsConfig(SmsConfig config)
        {
            if (config != null)
            {
                _session.Transact(session => session.Update(config));

                _helpersvc.Log(LogEntryType.Audit, null,
                               string.Format(
                                   "Sms  configuration was updated successfully {0}  id {1}, by {1}",
                                   config.Id, CurrentRequestData.CurrentUser.Id.ToString()), "Sms config Updated.");
                return(true);
            }
            return(false);
        }
Пример #13
0
        public bool SaveSmsConfig(SmsConfig config)
        {
            if (config != null)
            {
                _session.Transact(session => session.Save(config));
                //_helpersvc.Log(LogEntryType.Audit, null,
                //               string.Format(
                //                   "New Sms saved {0} , SMS ID {1}, by {2}",
                //                   sms.Id, CurrentRequestData.CurrentUser.Id.ToString()), "Sms Added.");

                return(true);
            }
            return(false);
        }
Пример #14
0
        public IActionResult SmsInsertOrUpdate(int?id)
        {
            SmsConfig smsConfig = new SmsConfig();

            if (id == null)
            {
                return(View(smsConfig));
            }
            smsConfig = new SmsConfigImpl(ConnectionString).Get(id ?? default(int)).Result;
            if (smsConfig == null)
            {
                return(NotFound());
            }
            return(View(smsConfig));
        }
Пример #15
0
        public static string SendMessage(string sendNum, string sendContent, string sendType, string sendTime, string reserve)
        {
            SmsConfig     smsConfig = SiteConfig.SmsConfig;
            string        str       = Guid.NewGuid().ToString();
            StringBuilder builder   = new StringBuilder();

            builder.Append("ID=");
            builder.Append(str);
            builder.Append("&UserName="******"&SendNum=");
            builder.Append(sendNum);
            builder.Append("&Content=");
            builder.Append(sendContent);
            builder.Append("&SendTiming=");
            builder.Append(sendType);
            builder.Append("&SendTime=");
            builder.Append(sendTime);
            builder.Append("&Reserve=");
            builder.Append(reserve);
            builder.Append("&MD5String=");
            builder.Append(StringHelper.MD5GB2312(str + smsConfig.UserName + smsConfig.MD5Key + sendNum + sendContent + sendType + sendTime));
            string         s          = builder.ToString();
            Uri            requestUri = new Uri("http://sms.EasyOne.net/MessageGate2/MessageGate.aspx");
            HttpWebRequest request    = (HttpWebRequest)WebRequest.Create(requestUri);

            request.Accept    = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-silverlight, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */*";
            request.Referer   = "http://sms.EasyOne.net/MessageGate2/MessageGate.aspx";
            request.UserAgent = "Mozilla/4.0   (compatible;   MSIE   6.0;   Windows   NT   5.2;   SV1;   .NET   CLR   1.1.4322";
            request.Headers.Add("Accept-Language:   zh-cn");
            request.ServicePoint.Expect100Continue = false;
            byte[] bytes = Encoding.Default.GetBytes(s);
            request.Method        = "POST";
            request.ContentType   = "application/x-www-form-urlencoded";
            request.ContentLength = bytes.Length;
            using (Stream stream = request.GetRequestStream())
            {
                stream.Write(bytes, 0, bytes.Length);
            }
            Stream       responseStream = ((HttpWebResponse)request.GetResponse()).GetResponseStream();
            Encoding     encoding       = Encoding.Default;
            StreamReader reader         = new StreamReader(responseStream, encoding);
            string       str3           = reader.ReadToEnd();

            reader.Close();
            return(str3);
        }
Пример #16
0
        /// <summary>
        /// 使用SMS Sender组件
        /// </summary>
        /// <param name="providerType"><seealso cref="SmsProviderType"/></param>
        /// <param name="smsConfig"><seealso cref="SmsConfig"/>配置信息,根据providerType参数值配置对应的信息</param>
        /// <param name="connectionString">数据库连接字符串</param>
        /// <param name="sqlType">数据库类型</param>
        public static void Factory(SmsProviderType providerType, SmsConfig smsConfig, string connectionString, SqlProviderType sqlType)
        {
            var option = new MiddlewareOptions();

            switch (providerType)
            {
            case SmsProviderType.YunPian:
                option.SendProvider = new YunPianProvider(smsConfig as YuanPianConfig);
                break;
            }

            option.SqlConnectionString = connectionString;

            option.SqlType = sqlType;

            MiddlewareConfig.Options = option;
        }
Пример #17
0
            public ISmsSender Create()
            {
                // 短信发送者创建,从配置管理中读取当前的发送方式,并创建实例
                SmsConfig smsConfig = _configProvider.GetSmsConfig();

                Console.WriteLine(smsConfig.SmsSenderType);
                // Not good enough: Not decoupled from the implementation class of SmsSender
                switch (smsConfig.SmsSenderType)
                {
                case SmsSenderType.Console:
                    return(new ConsoleSmsSender());

                case SmsSenderType.HttpAPi:
                    return(new HttpApiSmsSender());

                default:
                    return(new HttpApiSmsSender());
                }
            }
Пример #18
0
        public async Task <IActionResult> SmsInsertOrUpdate(SmsConfig smsConfig)
        {
            if (ModelState.IsValid)
            {
                smsConfig.DataSign = Encryption
                                     .Md5Hash($"{smsConfig.AccountName}-{smsConfig.Mobile}-{smsConfig.Message}-{ExtendSettings.SecureKey}").ToLower();
                smsConfig.ServiceId = ExtendSettings.ServiceId;
                //smsConfig.AlertConfigId = 1;
                if (smsConfig.Id == 0)
                {
                    //create
                    await new SmsConfigImpl(ConnectionString).Add(smsConfig);
                }
                else
                {
                    await new SmsConfigImpl(ConnectionString).Update(smsConfig);
                }

                return(RedirectToAction("Alert"));
            }

            return(View(smsConfig));
        }
Пример #19
0
 public ResearchSmsServices(SmsConfig smsConfig, ILogger <ResearchSmsServices> logger)
 {
     _smsConfig = smsConfig;
     _logger    = logger;
 }
Пример #20
0
        /// <summary>
        /// 使用SMS Sender组件
        /// </summary>
        /// <param name="providerType"><seealso cref="SmsProviderType"/></param>
        /// <param name="smsConfig"><seealso cref="SmsConfig"/>配置信息,根据providerType参数值配置对应的信息</param>
        /// <param name="connectionString">数据库连接字符串</param>
        /// <param name="sqlType">数据库类型</param>
        /// <returns></returns>
        public static IApplicationBuilder UseSMSSenderMiddleware(this IApplicationBuilder builder, SmsProviderType providerType, SmsConfig smsConfig, string connectionString, SqlProviderType sqlType)
        {
            var option = new MiddlewareOptions();

            switch (providerType)
            {
            case SmsProviderType.YunPian:
                option.SendProvider = new YunPianProvider(smsConfig as YuanPianConfig);
                break;
            }

            option.SqlConnectionString = connectionString;

            option.SqlType = sqlType;

            return(UseSMSSenderMiddleware(builder, option));
        }
Пример #21
0
 public SmsService(IOptions <SmsConfig> options)
 {
     smsConfig        = options.Value;
     twilioRestClient = new TwilioRestClient(smsConfig.Sid, smsConfig.Token);
 }
Пример #22
0
 public ConfigProvider(SmsConfig smsConfig)
 {
     _smsConfig = smsConfig;
 }
Пример #23
0
        public static int Add(OrderFlowInfo orderFlowInfo, UserInfo userInfo, string cartId, int couponId, decimal trueTotalMoney)
        {
            decimal num5;
            int     num6;
            int     num7;

            if (string.IsNullOrEmpty(cartId))
            {
                return(1);
            }
            IList <ShoppingCartInfo> infoByCart = ShoppingCart.GetInfoByCart(cartId, false);

            if (infoByCart.Count <= 0)
            {
                return(2);
            }
            IList <ShoppingCartInfo> shoppingCartPresentInfoList = ShoppingCart.GetInfoByCart(cartId, true);
            OrderInfo orderInfo   = new OrderInfo();
            double    totalWeight = 0.0;
            decimal   totalMoney  = 0M;
            double    discount    = PaymentType.GetPaymentTypeById(orderFlowInfo.PaymentType).Discount;
            string    userName    = "";
            int       clientId    = 0;

            if (!userInfo.IsNull)
            {
                ProcessSubscriber(orderFlowInfo, userInfo);
                userName = userInfo.UserName;
                clientId = userInfo.ClientId;
            }
            AddOrder(orderFlowInfo, orderInfo, discount, userName, clientId);
            AddOrderItems(orderFlowInfo, infoByCart, shoppingCartPresentInfoList, orderInfo, ref totalWeight, ref totalMoney, userInfo);
            CheckPresentProject(orderFlowInfo, orderInfo, ref totalWeight, ref totalMoney, out num5, out num6, out num7);
            decimal     num8 = totalMoney;
            PackageInfo packageByGoodsWeight = Package.GetPackageByGoodsWeight(totalWeight);

            if (!packageByGoodsWeight.IsNull)
            {
                totalWeight += packageByGoodsWeight.PackageWeight;
            }
            decimal num9 = DeliverCharge.GetDeliverCharge(orderFlowInfo.DeliverType, totalWeight, orderFlowInfo.ZipCode, totalMoney, orderFlowInfo.NeedInvoice);

            totalMoney             += num9;
            orderInfo.MoneyGoods    = num8;
            orderInfo.ChargeDeliver = num9;
            if (couponId > 0)
            {
                orderInfo.MoneyTotal = trueTotalMoney;
                orderInfo.CouponId   = couponId;
            }
            else
            {
                orderInfo.MoneyTotal = totalMoney;
            }
            orderInfo.PresentMoney = num5;
            orderInfo.PresentExp   = num6;
            orderInfo.PresentPoint = num7;
            Update(orderInfo);
            ShoppingCart.Delete(cartId);
            SmsConfig smsConfig = SiteConfig.SmsConfig;

            if ((smsConfig.IsAutoSendMessage && !string.IsNullOrEmpty(smsConfig.AdminPhoneNumber)) && !string.IsNullOrEmpty(smsConfig.OrderMessage))
            {
                AbstractMessageOfOrder order = new SmsOfOrder("", SendType.SendToAdmin, smsConfig.AdminPhoneNumber);
                order.Implementor = new OrderFlow(orderInfo, "");
                order.Send();
            }
            return(0x63);
        }
Пример #24
0
        public SmsConfig GetConfig()
        {
            SmsConfig config = _session.QueryOver <SmsConfig>().Take(1).SingleOrDefault();

            return(config);
        }