You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

65 lines
2.2 KiB

using FirebaseAdmin;
using FirebaseAdmin.Messaging;
using Google.Apis.Auth.OAuth2;
using Microsoft.AspNetCore.Mvc;
namespace firebase.net7API.Controllers
{
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
private readonly ILogger<WeatherForecastController> _logger;
public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}
[HttpGet(Name = "GetWeatherForecast")]
public IEnumerable<WeatherForecast> Get()
{
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
})
.ToArray();
}
[HttpPost(Name = "Post Notification")]
public async Task PushNotifications()
{
try
{
//var testApp = new AppOptions
//{
// Credential = GoogleCredential.FromFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "push-notification-api-c8613-firebase-adminsdk-pv5a8-1e337ca32a.json"))
//};
//FirebaseApp.Create(testApp);
var message = new Message()
{
Notification = new Notification
{
Title = "Hello",
Body = "03/11/23",
},
Token = "c9jYkaOeR0ypxJXqIuTfBr:APA91bEWUoncjxEyqMN2p5onHBRzF6N5XXrE48cu2TeGvhUFrNLdy6L6Yr72di4fXcc1HUINOk9HOs8wclnXLklNDQRpoPJ6l7GIdxJ87ym4BECXRyMfWhNw2VgxzCVImis4MEti7Enw",
};
var response = await FirebaseMessaging.DefaultInstance.SendAsync(message);
}
catch (Exception ex)
{
throw;
}
}
}
}