Ejemplo n.º 1
0
        public async Task <IActionResult> SendOneTimeCode([FromServices] IMessagePublisher messagePublisher)
        {
            var loginuser = await this.GetLoginUserAsync();

            var data = await this._login.GetUserPhone(loginuser.UserID);

            var phone = data.FirstOrDefault()?.Phone;

            if (ValidateHelper.IsEmpty(phone))
            {
                return(GetJsonRes("用户未绑定手机,无法实名制"));
            }

            var ran  = new Random((int)DateTime.UtcNow.Ticks);
            var code = string.Join(string.Empty, Com.Range(4).Select(x => ran.RealNext(9)).ToArray());

            //添加验证码
            await _login.AddVadlidationCode(new ValidationCodeEntity()
            {
                UserUID  = loginuser.UserID,
                Phone    = phone,
                Code     = code,
                CodeType = id_confirm_sms_type
            });

            await messagePublisher.PublishAsync(new UserPhoneBindSmsMessage()
            {
                Phone = phone, Code = code
            });

            return(SuccessJson());
        }