public ActionResult GetPassword(FormCollection fc) { var flag = false; var message = ""; string Phone = fc["Phone"]; var q = QueryBuilder.Create <Data.Users>().Equals(x => x.Phone, Phone); var model = Data.UsersDB.GETUsers(q); if (model == null) { flag = false; message = "不存在的电话号码."; } else { string Code = SMS.CreateCode(); flag = UsersDB.ChangePWD(model.ID, Encrypt.DES.Des_Encrypt(Code)); if (flag) { SMS.Send(Phone, Code); var smsModel = new Data.SMSCode(); smsModel.Code = Code; smsModel.CreateTime = DateTime.Now; smsModel.EndTime = smsModel.CreateTime.AddMinutes(10); smsModel.IsUse = false; smsModel.Phone = Phone; Data.SMSCodeDB.AddSMSCode(smsModel); } message = "新密码已发送到您号码为" + Phone + "的手机上."; } return(Json(new { success = flag, message = message }, JsonRequestBehavior.AllowGet)); }
public static bool SendCodes(string Phone = "", string Code = "") { try { Random rd = new Random(); Code = rd.Next(1000, 9999).ToString(); SMS.Send(Phone, Code, 1); var smsModel = new Data.SMSCode(); smsModel.Code = Code; smsModel.CreateTime = DateTime.Now; smsModel.EndTime = smsModel.CreateTime.AddMinutes(10); smsModel.IsUse = false; smsModel.Phone = Phone; Data.SMSCodeDB.AddSMSCode(smsModel); return(true); } catch { } return(false); }