Beispiel #1
0
        /// <summary>
        /// 发送验证码
        /// </summary>
        /// <param name="input">验证码Input</param>
        /// <returns></returns>
        private async Task SendValidateCode(ValidateCodeInput input, Action <string> sendAction)
        {
            string validateCode = new ValidateCoder().GetCode(6, ValidateCodeType.Number);
            var    codeEntity   = input.MapTo <ValidateCode>();

            codeEntity.Code = validateCode;
            await ValidateCodeRepo.InsertAsync(codeEntity);

            sendAction(validateCode);
        }
        /// <summary>
        /// 发送验证码
        /// </summary>
        /// <param name="codeKey">验证码Key</param>
        /// <param name="validateType">验证方式</param>
        /// <param name="codeType">验证码类型</param>
        /// <param name="sendAction">发送委托</param>
        /// <returns>业务操作结果</returns>
        private async Task <OperationResult> SendValidateCode(string codeKey, ValidateType validateType, CodeType codeType, Action <string> sendAction)
        {
            codeKey.CheckNotNull("codeKey");
            sendAction.CheckNotNull("sendAction");

            string validateCode = new ValidateCoder().GetCode(6, ValidateCodeType.Number);
            var    codeEntity   = new ValidateCode()
            {
                CodeKey      = codeKey,
                Code         = validateCode,
                ValidateType = validateType,
                CodeType     = codeType
            };
            var result = await ValidateCodeRepo.InsertAsync(codeEntity);

            sendAction(validateCode);
            return(new OperationResult(OperationResultType.Success, "验证码发送成功", validateCode));
        }
Beispiel #3
0
        /// <summary>
        /// 获取用户注册验证码
        /// </summary>
        /// <param name="phoneNo">手机号</param>
        /// <param name="codeType"></param>
        /// <returns>业务操作结果</returns>
        public async Task <OperationResult> GetSmsValidateCode(string phoneNo, CodeType codeType)
        {
            string validateCode = new ValidateCoder().GetCode(6, ValidateCodeType.Number);
            var    codeEntity   = new ValidateCode()
            {
                PhoneNo  = phoneNo,
                Code     = validateCode,
                CodeType = codeType
            };
            await ValidateCodeRepo.InsertAsync(codeEntity);

            //发送手机短信
            var smsContent = "您本次的验证码为" + validateCode + ",工作人员不会向您索要此验证码,请勿向任何人泄露。[右行养车]";

            Sms.Send(phoneNo, 1, smsContent);


            return(new OperationResult(OperationResultType.Success, "验证码发送成功", validateCode));
        }
        // public IUserContract UserContract { get; set; }
        /// <summary>
        /// 获取手机验证码
        /// </summary>
        /// <param name="phoneNo">手机号</param>
        /// <param name="codeType"></param>
        /// <returns>业务操作结果</returns>
        public async Task <OperationResult> GetSmsValidateCode(string phoneNo, CodeType codeType)
        {
            var    user         = UserInfos.Count(x => x.SysUser.PhoneNumber == phoneNo);
            string validateCode = new ValidateCoder().GetCode(6, ValidateCodeType.Number);
            var    codeEntity   = new ValidateCode()
            {
                CodeKey      = phoneNo,
                Code         = validateCode,
                ValidateType = ValidateType.手机,
                CodeType     = codeType
            };
            await ValidateCodeRepo.InsertAsync(codeEntity);

            if (codeType == CodeType.临时密码 || codeType == CodeType.找回密码)
            {
                if (user == 0)
                {
                    return(new OperationResult(OperationResultType.NoChanged, "此帐号还未注册", 0));
                }
                var results = SendMsg53kf.HttpGet((int)codeType, validateCode, phoneNo);
                if (results.code == 0)
                {
                    return(new OperationResult(OperationResultType.Success, "验证码发送成功,注意查看短信", 0));
                }
                return(new OperationResult(OperationResultType.Error, "短信系统繁忙,请稍后再试", 0));
            }
            else
            {
                if (user > 0)
                {
                    return(new OperationResult(OperationResultType.NoChanged, "此帐号已注册", 0));
                }
                var result = SendMsg53kf.HttpGet((int)codeType, validateCode, phoneNo);
                if (result.code == 0)
                {
                    return(new OperationResult(OperationResultType.Success, "验证码发送成功,注意查看短信", 0));
                }
                return(new OperationResult(OperationResultType.Error, "短信系统繁忙,请稍后再试", 0));
            }
        }