//检测验证码是否正确 private bool IfIdentifyingCodeCorrect(DBMA1DataContext dbma1, string phoneNum, string identifyingCode, string businessType) { //找到最新一条验证码 U004 identifyingCodeRecord = (from c in dbma1.U004s where c.phone == phoneNum //最新发送的验证码 && c.sendTime == (dbma1.U004s.Where(o => o.phone == phoneNum && o.businessType == businessType).Max(p => p.sendTime)) select c).FirstOrDefault(); if (identifyingCodeRecord == null) { return(false); } //验证码是否已经过期,过期时间为20分钟 int deadlineMinites = 20; TimeSpan ts = DateTime.Now - identifyingCodeRecord.sendTime; if (ts.Minutes > deadlineMinites) { return(false); } //验证验证码是否正确 return(identifyingCodeRecord.identifyingCode == identifyingCode ? true : false); }
//验证码记录写入到数据库中 private void IdentifyingCodeInsertIntoDB(DBMA1DataContext dbma1, string phoneNum, string identifyingCode, string businessType) { //获取编码 string tableName = "U004"; int SNDigitLength = 6; string prefix = "UA"; string max33SN = Comm.C101.FC10102(tableName, SNDigitLength, prefix); U004 u004 = new U004(); u004.smIdentifyingCodeRecordSN = max33SN; u004.phone = phoneNum; u004.identifyingCode = identifyingCode; u004.sendTime = DateTime.Now; u004.businessType = businessType; dbma1.U004s.InsertOnSubmit(u004); }
//判断是否需要新的验证码。验证码过期时间为20分钟 private string IfIdentifyCodePastDue(DBMA1DataContext dbma1, string phoneNum, string businessType) { DateTime dt = DateTime.Now.AddMinutes(-20); U004 identifyingCodeRecord = (from c in dbma1.U004s where c.phone == phoneNum && c.businessType == businessType && c.sendTime > dt select c).FirstOrDefault(); if (identifyingCodeRecord == null) { return(null); } else { return(identifyingCodeRecord.identifyingCode); } }