@ -0,0 +1,14 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace BCS.BMC.FirebaseCloudMessaging.Dto | |||||
{ | |||||
public class FcmNotificationSetting | |||||
{ | |||||
public string SenderId { get; set; } | |||||
public string ServerKey { get; set; } | |||||
} | |||||
} |
@ -0,0 +1,17 @@ | |||||
using Newtonsoft.Json; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace BCS.BMC.FirebaseCloudMessaging.Dto | |||||
{ | |||||
public class FireBaseResponseModel | |||||
{ | |||||
[JsonProperty("isSuccess")] | |||||
public bool IsSuccess { get; set; } | |||||
[JsonProperty("message")] | |||||
public string Message { get; set; } | |||||
} | |||||
} |
@ -0,0 +1,38 @@ | |||||
using Newtonsoft.Json; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace BCS.BMC.FirebaseCloudMessaging.Dto | |||||
{ | |||||
public class NotificationModel | |||||
{ | |||||
[JsonProperty("deviceId")] | |||||
public string DeviceId { get; set; } | |||||
[JsonProperty("isAndroidDevice")] | |||||
public bool IsAndroidDevice { get; set; } | |||||
[JsonProperty("title")] | |||||
public string Title { get; set; } | |||||
[JsonProperty("body")] | |||||
public string Body { get; set; } | |||||
} | |||||
public class GoogleNotification | |||||
{ | |||||
public class DataPayload | |||||
{ | |||||
[JsonProperty("title")] | |||||
public string Title { get; set; } | |||||
[JsonProperty("body")] | |||||
public string Body { get; set; } | |||||
} | |||||
[JsonProperty("priority")] | |||||
public string Priority { get; set; } = "high"; | |||||
[JsonProperty("data")] | |||||
public DataPayload Data { get; set; } | |||||
[JsonProperty("notification")] | |||||
public DataPayload Notification { get; set; } | |||||
} | |||||
} |
@ -0,0 +1,44 @@ | |||||
using FirebaseAdmin.Messaging; | |||||
using System.Threading.Tasks; | |||||
using FirebaseAdmin; | |||||
using Google.Apis.Auth.OAuth2; | |||||
using System; | |||||
namespace BCS.BMC.FirebaseCloudMessaging | |||||
{ | |||||
public class FirebaseNotificationAppService : IFirebaseNotificationAppService | |||||
{ | |||||
public FirebaseNotificationAppService() | |||||
{ | |||||
if (FirebaseApp.DefaultInstance is null) | |||||
{ | |||||
FirebaseApp.Create(new AppOptions() | |||||
{ | |||||
Credential = GoogleCredential.FromFile("firechat-57601-firebase-adminsdk-anscp-e04366c4d4.json") | |||||
}); | |||||
} | |||||
} | |||||
public static async Task<string> SendNotification(string fcmToken, Notification notification) | |||||
{ | |||||
try | |||||
{ | |||||
var message = new Message() | |||||
{ | |||||
Notification = notification, | |||||
Token = fcmToken, | |||||
}; | |||||
return await FirebaseMessaging.DefaultInstance.SendAsync(message) ; | |||||
} | |||||
catch(Exception ex) | |||||
{ | |||||
throw ex; | |||||
} | |||||
} | |||||
} | |||||
} |
@ -0,0 +1,11 @@ | |||||
using Abp.Application.Services; | |||||
using FirebaseAdmin.Messaging; | |||||
using System.Threading.Tasks; | |||||
namespace BCS.BMC.FirebaseCloudMessaging | |||||
{ | |||||
public interface IFirebaseNotificationAppService : IApplicationService | |||||
{ | |||||
// Task<string> SendNotification(string fcmToken, Notification notification); | |||||
} | |||||
} |
@ -0,0 +1,29 @@ | |||||
using BCS.BMC.Controllers; | |||||
using BCS.BMC.FirebaseCloudMessaging; | |||||
using FirebaseAdmin.Messaging; | |||||
using Microsoft.AspNetCore.Mvc; | |||||
using System.Collections.Generic; | |||||
using System.Threading.Tasks; | |||||
namespace BCS.BMC.Web.Controllers | |||||
{ | |||||
//[Route("api/notification")] | |||||
//[ApiController] | |||||
public class FirebaseNotificationController : BMCControllerBase | |||||
{ | |||||
private readonly FirebaseNotificationAppService _notificationService; | |||||
public FirebaseNotificationController(FirebaseNotificationAppService notificationService) | |||||
{ | |||||
_notificationService = notificationService; | |||||
} | |||||
[Route("send")] | |||||
[HttpPost] | |||||
public async Task<IActionResult> Notification(string fcmToken, [FromBody] Notification notification) | |||||
{ | |||||
var result = await FirebaseNotificationAppService.SendNotification(fcmToken, notification); | |||||
return Ok(result); | |||||
} | |||||
} | |||||
} |
@ -0,0 +1,12 @@ | |||||
{ | |||||
"type": "service_account", | |||||
"project_id": "firechat-57601", | |||||
"private_key_id": "e04366c4d4ad7167925421faaf7daf868cd5c686", | |||||
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCZwdt1kWg3mX8/\nXAdaECug6Kp9d3cfXshJLjZRtzUyeC7nkE10Ld0hhgxUH/5Fopu2vjTM0eq3NSNi\nte2ulpcEf4yObF5ZQEIeBvdf7uhvnvk1T+o/OcldkFyybWxSzCLwHWrS+eNkxKKP\nCbpXQuZ5v5g95p9FGFr9zM29gMB1FH1l0IiOh5UwGpTo39Glsdalw7OFDKYkWl0u\noGQ0qsO+As/MQKyYw4cJqIz6h8CX4WuloZhfKLv+KW8jwjN01UrlRNJQiJazSHYV\nLb9sP9WkGnVRnhXNtUy/vy6Cd5xSmd1wCPByNao04tlXPdBSwydqPsBmFjsSUX9V\nYg9Y5X6dAgMBAAECggEAEPr6x0TJXf04CKxGLOkaQwlO7XpIZTuCIlWAhDfCdTzB\nRADeEkA6ap2zi4WDqaG9UUo3lI3I6SDCNAA5gTgk8hyP+O6ji3ca64FYx8x0+QF1\nLjERgpgEKAQYaKVy+sCL9I6bId+dAEpDAEmnvZlS0LabE+2oleiMVqPL7kC41cpt\n9CVgjFUb8IaziGXkCBPboHt/MFs6bYBUJFAonME7O2hN3k9n4TSPcdjUvF+FrH/s\nN/GfimGqhRADX3jEONdiFuD77TTJMa6HcdeSnH2A9LbcDJGLb9dfLitJT0M8xbr1\nbkBA6SVe/RMfmYiyd1KfYmtvNnTvTEnJvIWfLLxo1QKBgQDQ85VVJAouBlbcSOqt\nS9qg9m7ze+dPHrt20kDRVZA8eglCjlQQTBbz3vbhFG8epL1i6r8NPi8SJt8UoQNM\ntxRQs2GRldOnEF0pSiwbbpk+XSAwTTt6DfOVbGSz+Z1LksKFrEEUAkNgem9S2+Zt\nCqHVkXxJxLkJpQ2qU+CPrqAm3wKBgQC8YMIgaKCZS8q485H+usiKmPLtSqYqv2Uw\nEujxkr6Esj25ev/bcBaIorJJm9Uk3ffUt2yZ3cmcNZfMsXQUdzEas/FHOxOY1Ria\n6dBCVKJy1oGC4HaOovLDMOLTrCUfcauJYdbRLOLBbhIRRqoGbva+dM8Xhdozfna6\ntvGlT242AwKBgDReJ/oLq0V3r0NMPwypqySWPp5lWkZ5FFCmRzpvsFOH3lRA6Y6g\nE0yRf9xPS74pWZG19aXzBMcO2PAJnpMWe0/ydSyQmVgQgNi9Tyqc4GlB27RfVt2z\nK24ymVaF48cyA/COiEzkeFBwvv/MPwbrGD43VSgD1sA1DqS2mtxHzrmPAoGATnY6\nxUbvBYrFEE4bVC82Ukwsetup5Io9uk1WCzCk/B5FiVkK8rp4GEcz3Wbz21w82rPf\nnyL6036bEJ4lDFUs9cNXTuTzX6f6jKOwo8AevZhM71dQ6k5CsTxObf34pGUzHpDK\n6es5M3oGOn3lWbKkQWXj0BdncCVPjKugcMtpy0MCgYAGPZTc0C2tPFPWavMfHcrq\nAUlVVkENELi41AcensgX+dbMQNJ8ePB4u2s5AEECbTGvG+NHIpfHOTr8bN/uw3PG\n7vPIsrfNuONkc13uhWF4YtvANcx2rhLxma84Ey5Ai2kvx6fer+BRRK3Wr36n3AEw\nssODLddJnZESSdlIdsghLw==\n-----END PRIVATE KEY-----\n", | |||||
"client_email": "firebase-adminsdk-anscp@firechat-57601.iam.gserviceaccount.com", | |||||
"client_id": "101896998053383660888", | |||||
"auth_uri": "https://accounts.google.com/o/oauth2/auth", | |||||
"token_uri": "https://oauth2.googleapis.com/token", | |||||
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", | |||||
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-anscp%40firechat-57601.iam.gserviceaccount.com" | |||||
} |