41 lines
1.3 KiB
C#
41 lines
1.3 KiB
C#
using JSAPI.Dtos;
|
|
using System.Text;
|
|
using System.Text.Json;
|
|
|
|
namespace JSAPI.classes
|
|
{
|
|
public class SendPringoService
|
|
{
|
|
private readonly HttpClient _http;
|
|
private readonly string _apiUrl;
|
|
private readonly string _apiKey;
|
|
|
|
public SendPringoService(HttpClient http, IConfiguration config)
|
|
{
|
|
_http = http;
|
|
_apiUrl = config["PringoApiURl"] ?? config["PringoApiUrl"]
|
|
?? throw new InvalidOperationException("appsettings.json: PringoApiURl 이(가) 없습니다.");
|
|
_apiKey = config["PringoApiKey"]
|
|
?? throw new InvalidOperationException("appsettings.json: PringoApiKey 이(가) 없습니다.");
|
|
|
|
if (_http.BaseAddress is null)
|
|
_http.BaseAddress = new Uri(_apiUrl, UriKind.Absolute);
|
|
}
|
|
|
|
public async Task<(int Status, string Body, string? ContentType)> SendMailAsync(PringoParamDto pringoParam)
|
|
{
|
|
// 외부 사양과 완전히 동일한 바디 구성
|
|
var bodyParam = new SendPringoParamDto(_apiKey, "11", pringoParam);
|
|
|
|
var json = JsonSerializer.Serialize(bodyParam);
|
|
using var content = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
using var resp = await _http.PostAsync("json-send", content);
|
|
var respBody = await resp.Content.ReadAsStringAsync();
|
|
var contentType = resp.Content.Headers.ContentType?.ToString();
|
|
|
|
return ((int)resp.StatusCode, respBody, contentType);
|
|
}
|
|
}
|
|
}
|