97 lines
3.2 KiB
C#
97 lines
3.2 KiB
C#
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");
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Sends a push notification to the specified device token with the provided payload.
|
|
/// </summary>
|
|
/// <param name="deviceToken">The device token to send the notification to.</param>
|
|
/// <param name="payload">The payload of the push notification.</param>
|
|
/// <returns>An IActionResult indicating the result of the operation.</returns>
|
|
/// <response code="200">Push notification sent successfully.</response>
|
|
/// <response code="400">Invalid input parameters.</response>
|
|
/// <response code="500">Internal server error occurred.</response>
|
|
/// <response code="999">Service unavailable.</response>
|
|
[HttpPost("send")]
|
|
[CustomOperation("푸시전송", "저장된 양식으로, 사용자에게 푸시를 전송한다.", "푸시")]
|
|
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(APIResponseStatus<object>))]
|
|
public async Task<IActionResult> 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());
|
|
}
|
|
|
|
}
|
|
} |