diff --git a/SPMS.Infrastructure/Push/ApnsSender.cs b/SPMS.Infrastructure/Push/ApnsSender.cs index be66593..bd408e6 100644 --- a/SPMS.Infrastructure/Push/ApnsSender.cs +++ b/SPMS.Infrastructure/Push/ApnsSender.cs @@ -4,6 +4,7 @@ using System.Net.Http.Headers; using System.Security.Cryptography; using System.Text; using System.Text.Json; +using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Microsoft.IdentityModel.Tokens; using SPMS.Application.DTOs.Push; @@ -14,17 +15,21 @@ namespace SPMS.Infrastructure.Push; public class ApnsSender : IApnsSender { private const string ProductionHost = "https://api.push.apple.com"; + private const string SandboxHost = "https://api.sandbox.push.apple.com"; private const int MaxConcurrency = 50; private const int TokenRefreshMinutes = 50; private readonly HttpClient _httpClient; private readonly ILogger _logger; + private readonly string _apnsHost; private readonly ConcurrentDictionary _tokenCache = new(); - public ApnsSender(IHttpClientFactory httpClientFactory, ILogger logger) + public ApnsSender(IHttpClientFactory httpClientFactory, IHostEnvironment hostEnvironment, ILogger logger) { _httpClient = httpClientFactory.CreateClient("ApnsSender"); _logger = logger; + _apnsHost = hostEnvironment.IsDevelopment() ? SandboxHost : ProductionHost; + _logger.LogInformation("APNs 환경: {Host}", _apnsHost); } public async Task SendAsync( @@ -79,7 +84,7 @@ public class ApnsSender : IApnsSender string jwt, string bundleId, string deviceToken, string payload, CancellationToken cancellationToken) { - var url = $"{ProductionHost}/3/device/{deviceToken}"; + var url = $"{_apnsHost}/3/device/{deviceToken}"; using var request = new HttpRequestMessage(HttpMethod.Post, url) {