Пример #1
0
        public static string SendValidCode(string phone)
        {
            using (var db = new DataAccess())
            {
                var model = db.Students.FirstOrDefault(a => a.Phone == phone);
                var code  = SendMessage.GenerateRandomNumber(100000, 999999).ToString();

                if (model != null)
                {
                    model.Code = code;
                    model.DataChange_LastTime = DateTime.Now;
                    model.CodeSendTime        = DateTime.Now;
                    db.SaveChanges();
                }
                else
                {
                    Student entity = new Student();
                    entity.Phone               = phone;
                    entity.Code                = code;
                    entity.Password            = "";
                    entity.Address             = "";
                    entity.BirthDate           = DateTime.Now.AddYears(-20);
                    entity.CodeSendTime        = DateTime.Now;
                    entity.DataChange_LastTime = DateTime.Now;
                    entity.Data_CreateTime     = DateTime.Now;
                    entity.Email               = "";
                    entity.Image               = "";
                    entity.QQ       = "";
                    entity.RealName = "";
                    entity.Salt     = "";
                    entity.Sex      = false;
                    entity.UserName = "";
                    entity.Valid    = false;
                    db.Students.Add(entity);
                    db.SaveChanges();
                }

                SendMessage.Send(phone, "【孚咖韩语】您本次操作的验证码是" + code + ",有效期10分钟.客服:4000707822");
                return(code);
            }
        }