public async Task <TAuthMessageRecord?> CheckAuthMessageAsync(ISmsSender smsSender, string phoneNumberOrEmail, string message, TSendSmsRequestType useType, TAuthMessageType?type = null) { var type_ = type ?? GetDefaultAuthMessageType(); var lastEffectiveRecord = await GetMostRecentVerificationCodeWithoutChecksumAndMoDiscard(type_, phoneNumberOrEmail, useType); if (lastEffectiveRecord == null || lastEffectiveRecord.Content != message) { return(null); } // ↑ 上一条有效纪录不存在或者验证码值不相同,返回null if (!lastEffectiveRecord.EverCheck) // 如果这条纪录没有校验过 { lastEffectiveRecord.EverCheck = true; // 设置此条纪录已经校验过 } if (lastEffectiveRecord.CheckFailuresCount >= SMS.MaxCheckFailuresCount) { lastEffectiveRecord.Abandoned = true; } else { if (IsPhoneNumberOrEmail(type_) && smsSender != null && smsSender.SupportCheck) { /* var check_provide_result =*/ await smsSender.CheckSmsAsync(phoneNumberOrEmail, message); // 第三方提供商要求调用验证短信接口,返回值可忽略,由内部实现纪录错误日志 } lastEffectiveRecord.CheckSuccess = true; } if (!lastEffectiveRecord.CheckSuccess) { lastEffectiveRecord.CheckFailuresCount++; if (lastEffectiveRecord.CheckFailuresCount >= SMS.MaxCheckFailuresCount) { lastEffectiveRecord.Abandoned = true; // 验证错误次数太多,此条纪录标记废弃 } } await db.SaveChangesAsync(); return(lastEffectiveRecord); }
public Task <ICheckSmsResult> CheckSmsAsync(string number, string message, CancellationToken cancellationToken) { return(smsSender.CheckSmsAsync(number, message, cancellationToken)); }