Exemplo n.º 1
0
        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));
            }
        }
Exemplo n.º 2
0
        /// <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);
        }