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)) { var inputError = APIResponse.InvalidInputError; // inputError.status.message = "Deviece Toekn 오류"; return StatusCode(500,inputError); } if (payload == null) { var inputError = APIResponse.InvalidInputError; // inputError.status.message = "payload 입력 오류"; return StatusCode(500,inputError); } string uri = ""; string p12Path = ""; string p12PWPath = "/src/private/appleKeys.json"; // string p12PWPath = "private/appleKeys.json"; string apnsTopic = "me.myds.ipstein.acamate.AcaMate"; if (_env.IsDevelopment()) { uri = "https://api.sandbox.push.apple.com/"; p12Path = "/src/private/AM_Push_Sandbox.p12"; // p12Path = "private/AM_Push_Sandbox.p12"; } else { uri = "https://api.push.apple.com/"; p12Path = "/src/private/AM_Push.p12"; // p12Path = "private/AM_Push.p12"; } // ApnsPushService 인스턴스 생성 var pushService = new ApnsPushService(uri, p12Path, p12PWPath, apnsTopic); // 푸시 알림 전송 var result = await pushService.SendPushNotificationAsync(deviceToken, payload); if (result.Success) { return Ok(APIResponse.Success()); } else { return BadRequest(APIResponse.InternalSeverError()); } } }