using AcaMate.Common.Models; using AcaMate.V1.Models; using Microsoft.AspNetCore.Mvc; using AcaMate.V1.Services; namespace AcaMate.V1.Controllers; [ApiController] [Route("/api/v1/in/push")] [ApiExplorerSettings(GroupName = "공통")] public class PushController : ControllerBase { private readonly IWebHostEnvironment _env; public PushController(IWebHostEnvironment env) { _env = env; } [HttpGet()] [CustomOperation("푸시 확인", "저장된 양식을 확인 할 수 있다..", "푸시")] public IActionResult GetPushData() { return Ok("SEND"); } /// /// Sends a push notification to the specified device token with the provided payload. /// /// The device token to send the notification to. /// The payload of the push notification. /// An IActionResult indicating the result of the operation. /// Push notification sent successfully. /// Invalid input parameters. /// Internal server error occurred. /// Service unavailable. [HttpPost("send")] [CustomOperation("푸시전송", "저장된 양식으로, 사용자에게 푸시를 전송한다.(로컬 테스트 불가)", "푸시")] [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(APIResponseStatus))] public async Task SendPush(string deviceToken, [FromBody] Payload? payload) { if (string.IsNullOrWhiteSpace(deviceToken) || payload == null) return BadRequest(APIResponse.InvalidInputError()); // string uri = ""; // string p12Path = ""; // // string p12PWPath = "/src/private/appleKeys.json"; // // // 앱 번들 ID 입력 부분 // string apnsTopic = "me.myds.ipstein.acamate.AcaMate"; Func pushService = (isDevelopment,pw,topic) => { if (isDevelopment) { return new ApnsPushService( "https://api.sandbox.push.apple.com/", "/src/private/AM_Push_Sandbox.p12", pw, topic ); } else { return new ApnsPushService( "https://api.push.apple.com/", "/src/private/AM_Push.p12", pw, topic ); } }; // // if (_env.IsDevelopment()) // { // uri = "https://api.sandbox.push.apple.com/"; // p12Path = "/src/private/AM_Push_Sandbox.p12"; // } // else // { // uri = "https://api.push.apple.com/"; // p12Path = "/src/private/AM_Push.p12"; // } // // ApnsPushService 인스턴스 생성 // var pushService = new ApnsPushService(uri, p12Path, p12PWPath, apnsTopic); // // 푸시 알림 전송 // var result = await pushService.SendPushNotificationAsync(deviceToken, payload); var result = await pushService( _env.IsDevelopment(), "/src/private/appleKeys.json", "me.myds.ipstein.acamate.AcaMate" ).SendPushNotificationAsync(deviceToken, payload); if (result.Success) { return Ok(APIResponse.Success()); } else { return BadRequest(APIResponse.InternalSeverError()); } } }