public async Task SendVerificationSms(SendVerificationSmsInputDto input) { var code = RandomHelper.GetRandom(100000, 999999).ToString(); var cacheKey = AbpSession.ToUserIdentifier().ToString(); var cacheItem = new SmsVerificationCodeCacheItem { Code = code }; _cacheManager.GetSmsVerificationCodeCache().Set( cacheKey, cacheItem ); await _smsSender.SendAsync(input.PhoneNumber, L("SmsVerificationMessage", code)); }
public async Task SendVerificationSms() { var user = await GetCurrentUserAsync(); var code = RandomHelper.GetRandom(100000, 999999).ToString(); var cacheKey = AbpSession.ToUserIdentifier().ToString(); var cacheItem = new SmsVerificationCodeCacheItem { Code = code }; _cacheManager.GetSmsVerificationCodeCache().Set( cacheKey, cacheItem ); await _smsSender.SendCodeAsync(user.PhoneNumber, code); }
public async Task SendVerificationSms() { var user = await GetCurrentUserAsync(); var code = RandomHelper.GetRandom(100000, 999999).ToString(); var cacheKey = AbpSession.ToUserIdentifier().ToString(); var cacheItem = new SmsVerificationCodeCacheItem { Code = code }; _cacheManager.GetSmsVerificationCodeCache().Set( cacheKey, cacheItem ); await _smsSender.SendAsync(user.PhoneNumber, SettingManager.GetSettingValue(AppSettings.SMSManagement.UserIdentityValidateTemplateCode), "{\"code\":\"" + code + "\"}"); }
/// <summary> /// 创建验证码 /// </summary> /// <param name="phoneNumber">手机号码</param> /// <param name="tag">业务标记</param> /// <param name="repeatSecs">多少秒内不得重复发送</param> /// <param name="expiredTime">过期时间</param> /// <returns></returns> public virtual async Task <string> Create(string phoneNumber, string tag = null, int repeatSecs = 60, DateTime?expiredTime = null) { var code = RandomHelper.GetRandom(1000, 9999).ToString(); var cacheKey = $"{phoneNumber}_{tag}"; var outTime = DateTime.Now.AddSeconds(-repeatSecs); var cash = await _cacheManager.GetSmsVerificationCodeCache().GetOrDefaultAsync(cacheKey); //验证码长度为4,60s内不得重复发送 if (cash != null && cash.CreationTime >= outTime) { throw new UserFriendlyException(_appLocalizationManager.L("SmsRepeatSendTip")); } var cacheItem = new SmsVerificationCodeCacheItem { Code = code, ExpiredTime = expiredTime }; _cacheManager.GetSmsVerificationCodeCache().Set( cacheKey, cacheItem ); return(code); }