AcaMate_API/Program/V1/Controllers/PushController.cs
2024-11-30 01:09:51 +09:00

60 lines
1.6 KiB
C#

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");
}
[HttpPost("send")]
[CustomOperation("푸시전송", "저장된 양식으로, 사용자에게 푸시를 전송한다.", "푸시")]
public async Task<IActionResult> SendPush(string deviceToken, string title, string body, int badge)
{
var keysFilePath = "private/appleKeys.json";
var uri = "";
var p12FilePath = "";
if (_env.IsDevelopment())
{
uri = "https://api.sandbox.push.apple.com";
p12FilePath = "private/AM_Push_Sandbox.p12";
}
else
{
uri = "https://api.push.apple.com";
p12FilePath = "private/AM_Push.p12";
}
var apnsTopic = "me.myds.ipstien.acamate.AcaMate";
var pushService = new PushServiceWithP12(keysFilePath, p12FilePath, apnsTopic);
// 푸시 알림 전송
await pushService.SendPushAsync(uri, deviceToken, title, body, badge);
return Ok("Push notification sent.");
}
}