예제 #1
0
        public static void SendSMS(string number, string message)
        {
            if (string.IsNullOrEmpty(number))
            {
                throw new ArgumentNullException("number");
            }
            if (string.IsNullOrEmpty(message))
            {
                throw new ArgumentNullException("message");
            }
            if (!StudioSmsNotificationSettings.IsVisibleSettings || !StudioSmsNotificationSettings.Enable || !SmsProviderManager.Enabled())
            {
                throw new MethodAccessException();
            }

            var cacheKey = "smsCode_" + number;
            int count;

            int.TryParse(PhoneCache.Get <string>(cacheKey), out count);

            if (count >= 3)
            {
                throw new Exception(Resource.SmsTooMuchError);
            }
            PhoneCache.Insert(cacheKey, (++count).ToString(CultureInfo.InvariantCulture), DateTime.UtcNow.Add(TrustInterval));

            if ("log".Equals(ConfigurationManager.AppSettings["core.notify.postman"], StringComparison.InvariantCultureIgnoreCase))
            {
                Log.InfoFormat("Tenant {0} send sms to phoneNumber {1} Message: {2}", TenantProvider.CurrentTenantID, number, message);
                return;
            }

            number = new Regex("[^\\d+]").Replace(number, string.Empty);
            if (SmsProviderManager.SendMessage(number, message))
            {
                CoreContext.TenantManager.SetTenantQuotaRow(new TenantQuotaRow {
                    Tenant = TenantProvider.CurrentTenantID, Path = "/sms", Counter = 1
                }, true);
            }
        }