Exemplo n.º 1
0
        private BaseModel ServerValidateSMSCode(string smsCode, string mobileNum, DateTime dt2)
        {
            #region 数据库端验证smsCode
            SMSCodeModel smsCodeModel = smsCodeDAL.GetByMobileNum(mobileNum, dt2);
            if (smsCodeModel == null)
            {
                return(new BaseModel()
                {
                    Code = (int)CodeEnum.短信验证码无效, Msg = CodeMsgDAL.GetByCode((int)CodeEnum.短信验证码无效)
                });
            }
            if (smsCodeModel.UsedCount >= 3)
            {
                return(new BaseModel()
                {
                    Code = (int)CodeEnum.短信验证码3次输入错误失效, Msg = CodeMsgDAL.GetByCode((int)CodeEnum.短信验证码3次输入错误失效)
                });
            }
            if (smsCodeModel.CodeValue != smsCode)
            {
                smsCodeDAL.ValidateFail(smsCodeModel.Id);
                return(new BaseModel()
                {
                    Code = (int)CodeEnum.短信验证码无效, Msg = CodeMsgDAL.GetByCode((int)CodeEnum.短信验证码无效)
                });
            }
            #endregion

            return(new BaseModel()
            {
                Code = (int)CodeEnum.成功, Msg = string.Format(CodeMsgDAL.GetByCode((int)CodeEnum.成功), "成功")
            });
        }
Exemplo n.º 2
0
        private SMSCodeModel EntityToModel(DataRow dr)
        {
            if (dr != null)
            {
                SMSCodeModel smsCodeModel = new SMSCodeModel();
                smsCodeModel.Id = dr["Id"].ToInt();

                smsCodeModel.MobileNum  = dr["MobileNum"].ToString();
                smsCodeModel.CodeValue  = dr["CodeValue"].ToString();
                smsCodeModel.CreateTime = dr["CreateTime"].To <DateTime>();
                smsCodeModel.UsedCount  = dr["UsedCount"].ToInt();
                return(smsCodeModel);
            }
            return(null);
        }
Exemplo n.º 3
0
        public BaseModel ValidateSMSCode(string mobileNum, string smsCode, string requestIP)
        {
            try
            {
                #region 非数据库端验证mobileNum
                BaseModel cv_MobileNum = ClientValidateMobileNum(mobileNum);
                if (cv_MobileNum.Code != 0)
                {
                    return(cv_MobileNum);
                }
                #endregion
                #region 非数据库端验证smsCode
                BaseModel cv_SMSCode = ClientValidateSMSCode(smsCode);
                if (cv_SMSCode.Code != 0)
                {
                    return(cv_SMSCode);
                }
                #endregion

                #region 数据库端验证appId
                //BaseModel sv_AppId = ServerValidateAppId(appId, requestIP);
                //if (sv_AppId.Code != 0)
                //{
                //    return sv_AppId;
                //}
                #endregion

                DateTime dt  = DateTime.Now;
                DateTime dt2 = dt.AddMinutes(0 - ConfigHelper.SMSTime);

                #region 数据库端验证smsCode
                SMSCodeModel smsCodeModel = smsCodeDAL.GetByMobileNum(mobileNum, dt2);
                if (smsCodeModel == null)
                {
                    return(new BaseModel()
                    {
                        Code = (int)CodeEnum.短信验证码无效, Msg = CodeMsgDAL.GetByCode((int)CodeEnum.短信验证码无效)
                    });
                }
                if (smsCodeModel.UsedCount >= 3)
                {
                    return(new BaseModel()
                    {
                        Code = (int)CodeEnum.短信验证码3次输入错误失效, Msg = CodeMsgDAL.GetByCode((int)CodeEnum.短信验证码3次输入错误失效)
                    });
                }

                if (smsCodeModel.CodeValue == smsCode)
                {
                    return(new BaseModel()
                    {
                        Code = (int)CodeEnum.成功, Msg = string.Format(CodeMsgDAL.GetByCode((int)CodeEnum.成功), "成功")
                    });
                }
                else
                {
                    smsCodeDAL.ValidateFail(smsCodeModel.Id);
                    return(new BaseModel()
                    {
                        Code = (int)CodeEnum.短信验证码无效, Msg = CodeMsgDAL.GetByCode((int)CodeEnum.短信验证码无效)
                    });
                }
                #endregion
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
                return(new BaseModel()
                {
                    Code = (int)CodeEnum.系统异常, Msg = CodeMsgDAL.GetByCode((int)CodeEnum.系统异常)
                });
            }
        }