improvement: ApnsSender 환경별 APNs 호스트 자동 분기 (#273)
All checks were successful
SPMS_API/pipeline/head This commit looks good
All checks were successful
SPMS_API/pipeline/head This commit looks good
Reviewed-on: https://git.ipstein.myds.me/SPMS/SPMS_API/pulls/274
This commit is contained in:
commit
8ccde89dc0
|
|
@ -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<ApnsSender> _logger;
|
||||
private readonly string _apnsHost;
|
||||
private readonly ConcurrentDictionary<string, (string Token, DateTime ExpiresAt)> _tokenCache = new();
|
||||
|
||||
public ApnsSender(IHttpClientFactory httpClientFactory, ILogger<ApnsSender> logger)
|
||||
public ApnsSender(IHttpClientFactory httpClientFactory, IHostEnvironment hostEnvironment, ILogger<ApnsSender> logger)
|
||||
{
|
||||
_httpClient = httpClientFactory.CreateClient("ApnsSender");
|
||||
_logger = logger;
|
||||
_apnsHost = hostEnvironment.IsDevelopment() ? SandboxHost : ProductionHost;
|
||||
_logger.LogInformation("APNs 환경: {Host}", _apnsHost);
|
||||
}
|
||||
|
||||
public async Task<PushResultDto> 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)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user