/// <summary> /// 验证验证码的正确性 /// </summary> /// <param name="tel">账号</param> /// <param name="code">待验证的code</param> /// <param name="key">秘钥(用于加解密)</param> /// <returns></returns> public async Task <bool> VerifyCode(string tel, string code, string key) { var staffId = GetSTaffInfoByTel(tel).Id; using (IAuthCodeService authCodeService = new AuthCodeService()) { var authCode = await authCodeService.GetAllOrder(false).FirstOrDefaultAsync(); if (StringEncryptAndDecrypt.AESEncrypt(code, key) == authCode.Code) { if (DateTime.Now.AddMinutes(-3) <= authCode.CreatTime) { return(true); } else { return(false); } } else { return(false); } } }
/// <summary> /// 创建验证码 /// </summary> /// <param name="staffId">创建者Id</param> /// <param name="code">验证码</param> /// <returns></returns> public async Task CreateAuthCode(Guid staffId, string code) { using (IAuthCodeService authCodeService = new AuthCodeService()) { await authCodeService.CreateAsync(new AuthCode() { StaffId = staffId, Code = code }); } }