コード例 #1
0
        public async Task <bool> Handle(EnviarTokenSmsCommand message, CancellationToken cancellationToken)
        {
            if (!message.IsValid())
            {
                NotifyValidationErrors(message);
                return(await Task.FromResult(false));
            }

            try
            {
                var client = _httpAppService.CreateClient(_serviceManager.UrlVileve);

                var token = await _httpAppService.OnPost <Token, object>(client, message.RequestId, "v1/auth/login", new
                {
                    usuario = _serviceManager.UserVileve,
                    senha   = _serviceManager.PasswordVileve
                });

                if (token == null || string.IsNullOrWhiteSpace(token.AccessToken))
                {
                    await _bus.RaiseEvent(new DomainNotification(message.MessageType, "Usuário de integração não encontrado.", message));

                    return(await Task.FromResult(false));
                }

                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.AccessToken);

                var enviarTokenSms = await _httpAppService.OnPost <EnviarTokenSms, object>(client, message.RequestId, "v1/validacao-contato/enviar-token-sms", new
                {
                    numero_telefone = message.NumeroCelular
                });

                if (enviarTokenSms.Sucesso.Equals(false))
                {
                    await _bus.RaiseEvent(new DomainNotification(message.MessageType, "O sistema está momentaneamente indisponível, tente novamente mais tarde.", message));

                    return(await Task.FromResult(false));
                }
            }
            catch (Exception e)
            {
                _logger.Log(LogLevel.Error, e, JsonSerializer.Serialize(new
                {
                    message.RequestId,
                    e.Message
                }));

                await _bus.RaiseEvent(new DomainNotification(message.MessageType, "O sistema está momentaneamente indisponível, tente novamente mais tarde.", message));

                return(await Task.FromResult(false));
            }

            return(await Task.FromResult(true));
        }
コード例 #2
0
 public async Task EnviarTokenSms(string numeroCelular)
 {
     var enviarTokenSmsCommand = new EnviarTokenSmsCommand(numeroCelular);
     await _bus.SendCommand(enviarTokenSmsCommand);
 }