Unip.CentralRelacionamento.Client 1.1.0

dotnet add package Unip.CentralRelacionamento.Client --version 1.1.0
                    
NuGet\Install-Package Unip.CentralRelacionamento.Client -Version 1.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Unip.CentralRelacionamento.Client" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Unip.CentralRelacionamento.Client" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Unip.CentralRelacionamento.Client" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Unip.CentralRelacionamento.Client --version 1.1.0
                    
#r "nuget: Unip.CentralRelacionamento.Client, 1.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Unip.CentralRelacionamento.Client@1.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Unip.CentralRelacionamento.Client&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Unip.CentralRelacionamento.Client&version=1.1.0
                    
Install as a Cake Tool

Unip.CentralRelacionamento.Client

Cliente .NET para a API da Central de Relacionamento (UNIP). Envie SMS individualmente ou em lote, consulte o status de entrega e envie e-mails informando apenas a URL base e o token de acesso.

Compatibilidade

Alvo Plataformas
net47 .NET Framework 4.7, 4.7.1, 4.7.2, 4.8
netstandard2.0 .NET Core 3.1, .NET 5, 6, 7 e 8

Sem dependências externas.

Instalação

dotnet add package Unip.CentralRelacionamento.Client

Ou, no Package Manager Console:

Install-Package Unip.CentralRelacionamento.Client

Configuração

Você precisa de dois valores, ambos disponíveis na tela Meu cadastro do sistema, no bloco Dados da conta:

Valor Onde obter
URL base da API Campo URL base API
Token Campo Token

Não fixe esses valores no código. Mantenha-os em configuração (appsettings.json, Web.config, variáveis de ambiente ou cofre de segredos), pois mudam entre ambientes e o token é uma credencial.

Exemplo de configuração

appsettings.json:

{
  "CentralRelacionamento": {
    "BaseUrl": "",
    "Token": ""
  }
}

Uso

using Unip.CentralRelacionamento.Client;

var cliente = new CentralRelacionamentoClient(
    baseUrl: configuracao["CentralRelacionamento:BaseUrl"],
    token:   configuracao["CentralRelacionamento:Token"]);

Enviar um SMS

var envio = await cliente.EnviarSmsAsync("11999998888", "Sua matrícula foi confirmada.");

if (envio.Sucesso)
    Console.WriteLine($"Enviado. Id: {envio.Id}");
else
    Console.WriteLine($"Falhou: {envio.Status}");

Consultar o status de entrega

var status = await cliente.ConsultarStatusAsync(envio.Id);
Console.WriteLine(status.Status);          // ex.: "Entregue"
Console.WriteLine(status.StatusOriginal);  // ex.: "000 - Message Sent"

A entrega de SMS não é instantânea. Consulte alguns minutos após o envio e evite intervalos muito curtos (recomendado: a cada 5 minutos).

Enviar em lote

var lote = await cliente.EnviarLoteAsync(
    new[] { "11999998888", "11888887777" },
    "Prova amanhã às 10h. Não falte.");

Enviar e-mail

var envio = await cliente.EnviarEmailAsync(
    email:  "aluno@exemplo.com",
    titulo: "Confirmação de matrícula",
    texto:  "<p>Sua matrícula foi <b>confirmada</b>.</p>");

if (!envio.Sucesso)
    logger.LogWarning("E-mail não aceito: {Motivo}", envio.Mensagem);

O corpo é enviado em HTML, e a versão em texto simples é gerada automaticamente (melhora a entregabilidade). Você também pode enviar texto puro — as quebras de linha são preservadas e os caracteres especiais são tratados:

await cliente.EnviarEmailAsync(
    email:  "aluno@exemplo.com",
    titulo: "Confirmação de matrícula",
    texto:  "Prezado(a) aluno,\n\nSua matrícula foi confirmada.");
Remetente

Se você não informar nada, o remetente é definido pela conta do token utilizado:

Conta Remetente padrão
Objetivo Objetivo <no-reply@objetivo.br>
Demais contas UNIP <no-reply@unip.br>

Você também pode escolher o remetente, informando o nome de exibição que quiser:

await cliente.EnviarEmailAsync(
    email:     "aluno@exemplo.com",
    titulo:    "Resultado do simulado",
    texto:     "<p>Seu resultado já está disponível.</p>",
    remetente: "Sistema Simulado <no-reply@objetivo.br>");

O nome é livre, mas o endereço deve ser um dos dois autorizados:

Endereço Constante
no-reply@unip.br CentralRelacionamentoClient.RemetenteUnip
no-reply@objetivo.br CentralRelacionamentoClient.RemetenteObjetivo

Qualquer outro endereço é recusado (Sucesso = false), porque apenas esses domínios estão autorizados no provedor de envio — usar outro faria a mensagem ser bloqueada ou classificada como spam.

await cliente.EnviarEmailAsync(
    email:     "aluno@exemplo.com",
    titulo:    "Resultado do simulado",
    texto:     "Seu resultado já está disponível.",
    remetente: $"Sistema Simulado <{CentralRelacionamentoClient.RemetenteObjetivo}>");

Sucesso = true significa que o provedor aceitou a mensagem para entrega. A entrega na caixa do destinatário não é instantânea e depende do servidor de destino.

Injeção de dependência

O cliente é thread-safe e reutiliza a conexão HTTP. Registre-o como singleton para evitar esgotamento de sockets:

services.AddSingleton(sp =>
{
    var config = sp.GetRequiredService<IConfiguration>();
    return new CentralRelacionamentoClient(
        config["CentralRelacionamento:BaseUrl"],
        config["CentralRelacionamento:Token"]);
});

Com IHttpClientFactory:

services.AddHttpClient("central");

services.AddSingleton(sp =>
{
    var config  = sp.GetRequiredService<IConfiguration>();
    var factory = sp.GetRequiredService<IHttpClientFactory>();

    return new CentralRelacionamentoClient(
        baseUrl:    config["CentralRelacionamento:BaseUrl"],
        token:      config["CentralRelacionamento:Token"],
        httpClient: factory.CreateClient("central"));
});

Ao passar um HttpClient próprio, o Dispose do cliente não o libera — o ciclo de vida continua sob sua responsabilidade.

Tratamento de erros

  • Falhas de negócio (número inválido, mensagem recusada) não lançam exceção: verifique Sucesso e leia Status / Mensagem.
  • Falhas de transporte (HTTP 4xx/5xx) lançam CentralRelacionamentoException, que expõe CodigoStatus e Conteudo.
try
{
    var envio = await cliente.EnviarSmsAsync(telefone, mensagem);

    if (!envio.Sucesso)
        logger.LogWarning("SMS não enviado: {Motivo}", envio.Status);
}
catch (CentralRelacionamentoException ex)
{
    logger.LogError(ex, "Falha HTTP {Codigo}", ex.CodigoStatus);
}

Segurança

O token é derivado das suas credenciais e permite enviar mensagens em nome da sua conta. Trate-o como uma senha: nunca o exponha em código de front-end (JavaScript no navegador, apps mobile) nem em repositórios públicos. Ao trocar a senha, o token muda e as integrações precisam ser atualizadas.

Boas práticas

  • Envie o telefone com DDD + número; o cliente remove máscaras automaticamente.
  • Mantenha o SMS em até 149 caracteres — acima disso pode ser tarifado como 2 mensagens.
  • Para grandes volumes, use EnviarLoteAsync em vez de várias chamadas individuais.
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 is compatible.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.7

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.0 149 9/22/2026