public ActionResult Register(string mobile, string code) { try { //判断验证码是否正确 UserCheckMobile existCheckMobileUserInfo = CheckMobileService.GetLastCheckMobileInfo(mobile); if (code != existCheckMobileUserInfo.CheckCode) { return(Json(JsonHandler.CreateMessage(0, "验证码错误,请重新输入!"))); } //根据手机号码取出会员信息 var usermodel = WebUtils.Get <CustomerNew>(WebConfig.ApiBaseUrl + "WlxApi/GetCustomerBySql", mobile); //把openid等信息更新到万里信erp if (usermodel == null) { Tools.MessBox("test1"); InsertCustomerNew customer = new InsertCustomerNew(); customer.num = mobile; customer.openid = CurrentCustomer.OpenId; customer.wxname = CurrentCustomer.Name; var inserResult = WebUtils.Save <InsertCustomerNew>(WebConfig.ApiBaseUrl + "WlxApi/InsertVip", customer); Tools.MessBox("test2"); var url = DataUtils.GetRedirectToActionUrl(); return(Json(JsonHandler.CreateMessage(1, "注册成功", url), JsonRequestBehavior.AllowGet)); //return Json(JsonHandler.CreateMessage(0, "您不是线下会员,请到附近门店办理会员后再来关联"), JsonRequestBehavior.AllowGet); } updateCustomer updatcustomer = new updateCustomer(); updatcustomer.openid = CurrentCustomer.OpenId; updatcustomer.wx_name = CurrentCustomer.Name; updatcustomer.vpid = usermodel.c_identity.ToString(); var result = WebUtils.Save <updateCustomer>(WebConfig.ApiBaseUrl + "WlxApi/UpdateVip", updatcustomer); if (result) { Customer customer = new Customer(); customer.Phone = mobile; Session["Customer"] = customer; Tools.MessBox(string.Format("时间:{0},描述:{1}", DateTime.Now, customer.Phone), "//Log//Register//Session//"); var url = DataUtils.GetRedirectToActionUrl(); return(Json(JsonHandler.CreateMessage(1, "注册成功", url), JsonRequestBehavior.AllowGet)); } else { return(Json(JsonHandler.CreateMessage(0, "注册失败"), JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { Tools.MessBox(ex.ToString(), "//Log//Register//Exception"); return(Json(JsonHandler.CreateMessage(0, "注册失败", Url.Action("Index")), JsonRequestBehavior.AllowGet)); } }
/// <summary> /// 向数据库中插入一条新记录。 /// </summary> /// <param name="info">实体类</param> /// <returns>新插入记录的编号</returns> public UserCheckMobile InsertCheckMobileInfo(UserCheckMobile info) { using (EntityContext db = new EntityContext()) { info.ID = CommonUtil.GetNewID(); info.UpdateTime = DateTime.Now; db.UserCheckMobiles.Add(info); db.SaveChanges(); return(info); } }
public ActionResult SendCheckCode(string mobile) { CheckMobileStatus status = CheckMobileStatus.错误; string msg = ""; if (WLX.Utils.Validator.IsMobile(mobile)) { UserCheckMobile checkinfo = new UserCheckMobile(); checkinfo.Mobile = mobile; checkinfo.CheckCode = WLX.Utils.Utils2.GetRandomString(1, 6, "0123456789").ToUpper(); //checkinfo.UserID = onlineUserInfo.UserID; checkinfo.GetCodeTimes = 1; //发送短信验证码 status = SMSService.SendMobileCheckCode(checkinfo); switch (status) { case CheckMobileStatus.成功发送验证码: msg = "已发送验证码,请注意查收。"; break; case CheckMobileStatus.这个手机已经绑定: msg = "您已绑定手机,如需更改请输入新手机号码。"; break; case CheckMobileStatus.验证间隔时间太短: msg = "一分钟只能发送一次验证码,请稍后再试。"; break; case CheckMobileStatus.手机已被其他账户绑定: msg = "您填写的手机号码已绑定其他账户,如有疑问请咨询客服,谢谢。"; break; default: break; } } else { msg = "手机号码有误,请输入正确的手机号码。"; } if (status == CheckMobileStatus.成功发送验证码) { return(Content("已发送验证码至:" + mobile, "checkmobile.aspx?action=step2&mobile=" + mobile)); } else { return(Content(msg)); } }
/// <summary> /// 向数据表TaoXieUser_CheckMobile更新一条记录。 /// </summary> /// <param name="info">实体类</param> /// <returns>影响的行数</returns> public int UpdateCheckMobileInfo(UserCheckMobile info) { SqlParameter[] prams = new SqlParameter[6]; prams[0] = new SqlParameter("@ID", info.ID); prams[1] = new SqlParameter("@UserID", info.UserID); prams[2] = new SqlParameter("@Mobile", info.Mobile); prams[3] = new SqlParameter("@UpdateTime", info.UpdateTime); prams[4] = new SqlParameter("@CheckCode", info.CheckCode); prams[5] = new SqlParameter("@GetCodeTimes", info.GetCodeTimes); return(helper.ExecuteNonQuery(CheckMobileInfo_SQL_UPDATE, prams)); }
/// <summary> /// 得到 taoxieuser_checkmobile 数据实体 /// </summary> /// <param name="dr">dr</param> /// <returns>实体类</returns> public UserCheckMobile GetCheckMobileInfo(IDataReader dr) { UserCheckMobile Obj = new UserCheckMobile(); Obj.ID = ((dr["ID"]) == DBNull.Value) ? "" : dr["ID"].ToString(); Obj.UserID = ((dr["UserID"]) == DBNull.Value) ? "" : dr["UserID"].ToString(); Obj.Mobile = dr["Mobile"].ToString(); Obj.UpdateTime = ((dr["UpdateTime"]) == DBNull.Value) ? Convert.ToDateTime("1900-1-1") : Convert.ToDateTime(dr["UpdateTime"]); Obj.CheckCode = dr["CheckCode"].ToString(); Obj.GetCodeTimes = ((dr["GetCodeTimes"]) == DBNull.Value) ? 0 : Convert.ToInt32(dr["GetCodeTimes"]); return(Obj); }
/// <summary> /// 得到 taoxieuser_checkmobile 数据实体 /// </summary> /// <param name="row">row</param> /// <returns>实体类</returns> public UserCheckMobile GetCheckMobileInfo(DataRow row) { UserCheckMobile Obj = new UserCheckMobile(); if (row != null) { Obj.ID = ((row["ID"]) == DBNull.Value) ? "" : row["ID"].ToString(); Obj.UserID = ((row["UserID"]) == DBNull.Value) ? "" : row["UserID"].ToString(); Obj.Mobile = row["Mobile"].ToString(); Obj.UpdateTime = ((row["UpdateTime"]) == DBNull.Value) ? Convert.ToDateTime("1900-1-1") : Convert.ToDateTime(row["UpdateTime"]); Obj.CheckCode = row["CheckCode"].ToString(); Obj.GetCodeTimes = ((row["GetCodeTimes"]) == DBNull.Value) ? 0 : Convert.ToInt32(row["GetCodeTimes"]); } else { return(null); } return(Obj); }
/// <summary> /// 向数据库中插入一条新记录。带事务 /// </summary> /// <param name="sp">事务对象</param> /// <param name="info">实体类</param> /// <returns>新插入记录的编号</returns> public int InsertCheckMobileInfo(SqlTransaction sp, UserCheckMobile info) { // 声明参数数组并赋值 SqlParameter[] _param = { SqlHelper.MakeParam(PARA_CheckMobileInfo_CheckID, SqlDbType.NVarChar, 0, info.ID), SqlHelper.MakeParam(PARA_CheckMobileInfo_UserID, SqlDbType.NVarChar, 0, info.UserID), SqlHelper.MakeParam(PARA_CheckMobileInfo_Mobile, SqlDbType.NVarChar, 0, info.Mobile), SqlHelper.MakeParam(PARA_CheckMobileInfo_UpdateTime, SqlDbType.DateTime, 0, info.UpdateTime), SqlHelper.MakeParam(PARA_CheckMobileInfo_CheckCode, SqlDbType.NVarChar, 0, info.CheckCode), SqlHelper.MakeParam(PARA_CheckMobileInfo_GetCodeTimes, SqlDbType.Int, 0, info.GetCodeTimes) }; // 定义返回的ID int outID = 0; SqlHelper.ExecuteNonQuery(sp, CommandType.Text, CheckMobileInfo_SQL_INSERT, _param); // 返回 return(outID); }
/// <summary> /// 获取手机验证吗,并发送短信通知。此方法有判断重复的手机号 /// </summary> /// <param name="chanceInfo"></param> /// <returns></returns> public static CheckMobileStatus SendMobileCheckCode(UserCheckMobile checkInfo) { CheckMobileStatus result = CheckMobileStatus.成功发送验证码; bool haveChance = false; int interval = 2;//间隔几分钟 Customer existCheckMobileUserInfo = UserService.GetUserInfoByCheckdMobile(checkInfo.Mobile); if (existCheckMobileUserInfo == null) { //CheckMobileService checkMobileService = new CheckMobileService(); UserCheckMobile lastCheckInfo = CheckMobileService.GetLastCheckMobileInfo(checkInfo.Mobile); if (lastCheckInfo == null) { //不存在相关记录,则可以发送 haveChance = true; } else { //当前时间已经超过间隔时间 if (lastCheckInfo.UpdateTime.AddMinutes(interval) < DateTime.Now) { haveChance = true; } else { haveChance = false; result = CheckMobileStatus.验证间隔时间太短; } } //符合发放条件 if (haveChance) { CheckMobileService check = new CheckMobileService(); if (lastCheckInfo != null) { lastCheckInfo.Mobile = checkInfo.Mobile; lastCheckInfo.CheckCode = checkInfo.CheckCode; lastCheckInfo.GetCodeTimes = lastCheckInfo.GetCodeTimes + 1; lastCheckInfo.UpdateTime = DateTime.Now; check.UpdateCheckMobileInfo(lastCheckInfo); } else { check.InsertCheckMobileInfo(checkInfo); } //变更模板获取 和 短信接口引用,每天只能发送3条验证手机短信。防止恶意刷短信 //string msgContent = string.Format(SMSFormat.SMS_CHECKMOBILE, checkInfo.CheckCode); bool send = SMS_SendOnly(checkInfo.Mobile, checkInfo.CheckCode, string.Empty, checkInfo.UserID, 3); if (send) { result = CheckMobileStatus.成功发送验证码; } else { result = CheckMobileStatus.错误; } } } else { if (existCheckMobileUserInfo.ID == checkInfo.UserID) { result = CheckMobileStatus.这个手机已经绑定; } else { result = CheckMobileStatus.手机已被其他账户绑定; } } return(result); }