From 420a036c36964eb75a5d88550e47859fbe7910a7 Mon Sep 17 00:00:00 2001 From: SEAN Date: Tue, 3 Mar 2026 10:37:35 +0900 Subject: [PATCH] =?UTF-8?q?improvement:=20ApnsSender=20=ED=99=98=EA=B2=BD?= =?UTF-8?q?=EB=B3=84=20APNs=20=ED=98=B8=EC=8A=A4=ED=8A=B8=20=EC=9E=90?= =?UTF-8?q?=EB=8F=99=20=EB=B6=84=EA=B8=B0=20(#273)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #273 --- SPMS.Infrastructure/Push/ApnsSender.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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) {