/// <summary> /// 发送手机短信所用方法 /// </summary> /// <param name="mobile"></param> /// <returns></returns> private void insert_validityrecord(string sID, int iHours, string sBody, string sCode, int iType) { try { using (var db = new shhouseEntities()) { var user_validityrecord = new user_validityrecord() { userid = int.Parse(sID), validity = DateTime.Now.AddHours(24), checkcode = sCode, codetype = iType, state = "0", body = "" }; db.user_validityrecord.Add(user_validityrecord); db.SaveChanges(); } } catch { } }
/// <summary> /// 发送验证短信验证码 http://192.168.1.223/GR_Home/SendSmsCode /// </summary> /// <param name="mobile"></param> /// <returns></returns> public string SendSmsCode(string mobile) { bool flg = false; string sID = "", sEmail = "", sMobile = ""; if (!string.IsNullOrEmpty(mobile)) { //查询用户信息 using (var db = new shhouseEntities()) { var persons = db.user_details.Where(x => x.mobile == mobile).FirstOrDefault(); //var persons = (from u in db.user_details join b in db.user_member on u.userid equals b.userid where b.mobile == mobile select u).FirstOrDefault(); if (persons != null) { sID = persons.userid.ToString(); sEmail = persons.email; sMobile = persons.mobile; flg = true; } else { sID = "0"; sEmail = null; sMobile = mobile; flg = true; } } if (flg) { Random random = new Random(); string sCode = random.Next(111111, 1000000).ToString(); if (SMS.SendSMS_New(sMobile, "验证码:" + sCode + " 【e房网】") != "100") { return(JsonConvert.SerializeObject(new repmsg { state = 2, msg = "短信发送失败,请稍侯再试", data = null })); } else { //添加到数据库 using (var db = new shhouseEntities()) { var user_validityrecord = new user_validityrecord() { userid = int.Parse(sID), //用户id validity = DateTime.Now.AddHours(24), //有效期 checkcode = sCode, //验证码 codetype = 1, //类型 发短信为1 发邮件为2 这里默认为1 state = "0", //是否有效 状态 body = "", //描述 Mobile = mobile //新增用户手机号码 }; db.user_validityrecord.Add(user_validityrecord); db.SaveChanges(); } } } return(JsonConvert.SerializeObject(new repmsg { state = 1, msg = "发送成功", data = null })); } return(JsonConvert.SerializeObject(new repmsg { state = 2, msg = "发送失败", data = null })); }