BMC: Add GetNotification Method
This commit is contained in:
parent
9938bbabc7
commit
c38e4e6599
@ -9,11 +9,11 @@ namespace BCS.BMC.FirebaseCloudMessaging.Dto
|
||||
{
|
||||
public class NotificationModel
|
||||
{
|
||||
[JsonProperty("deviceId")]
|
||||
public string DeviceId { get; set; }
|
||||
[JsonProperty("isAndroidDevice")]
|
||||
public bool IsAndroidDevice { get; set; }
|
||||
[JsonProperty("title")]
|
||||
//[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; }
|
||||
|
@ -6,13 +6,15 @@ using System;
|
||||
using BCS.BMC.FirebaseCloudMessaging.Dto;
|
||||
using System.Collections.Generic;
|
||||
using Abp.Json;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace BCS.BMC.FirebaseCloudMessaging
|
||||
{
|
||||
public class FirebaseNotificationAppService : IFirebaseNotificationAppService
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public FirebaseNotificationAppService()
|
||||
public FirebaseNotificationAppService(ILogger logger)
|
||||
{
|
||||
if (FirebaseApp.DefaultInstance is null)
|
||||
{
|
||||
@ -21,27 +23,31 @@ namespace BCS.BMC.FirebaseCloudMessaging
|
||||
Credential = GoogleCredential.FromFile("firechat-57601-firebase-adminsdk-anscp-e04366c4d4.json")
|
||||
});
|
||||
}
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
|
||||
public static async Task<BatchResponse> SendNotification( FireBaseResponseModel notification)
|
||||
public async Task<BatchResponse> SendNotification(FireBaseResponseModel notification)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
var message = new MulticastMessage()
|
||||
{
|
||||
Notification = notification.notification,
|
||||
Tokens = notification.FcmToken,
|
||||
};
|
||||
var message = new MulticastMessage()
|
||||
{
|
||||
Notification = notification.notification,
|
||||
Tokens = notification.FcmToken,
|
||||
};
|
||||
|
||||
var response = await FirebaseMessaging.DefaultInstance.SendMulticastAsync(message);
|
||||
return response;
|
||||
}
|
||||
catch(Exception ex)
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
public async Task GetNotification(NotificationModel notification)
|
||||
{
|
||||
_logger.LogInformation("Bwac Notifications" + notification);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Abp.Application.Services;
|
||||
using BCS.BMC.FirebaseCloudMessaging.Dto;
|
||||
using FirebaseAdmin.Messaging;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -6,6 +7,7 @@ namespace BCS.BMC.FirebaseCloudMessaging
|
||||
{
|
||||
public interface IFirebaseNotificationAppService : IApplicationService
|
||||
{
|
||||
// Task<string> SendNotification(string fcmToken, Notification notification);
|
||||
Task<BatchResponse> SendNotification(FireBaseResponseModel notification);
|
||||
Task GetNotification(NotificationModel notification);
|
||||
}
|
||||
}
|
||||
|
@ -12,23 +12,29 @@ using System.Threading.Tasks;
|
||||
namespace BCS.BMC.Web.Controllers
|
||||
{
|
||||
|
||||
[Route("api/[controller]/SendNotification")]
|
||||
[Route("api/[controller]/[action]")]
|
||||
public class FirebaseNotificationController : BMCControllerBase
|
||||
{
|
||||
private readonly FirebaseNotificationAppService _notificationService;
|
||||
private readonly IFirebaseNotificationAppService _notificationService;
|
||||
|
||||
public FirebaseNotificationController(FirebaseNotificationAppService notificationService)
|
||||
public FirebaseNotificationController(IFirebaseNotificationAppService notificationService)
|
||||
{
|
||||
_notificationService = notificationService;
|
||||
}
|
||||
|
||||
//[Route("SendNotification")]
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Notification( [FromBody] FireBaseResponseModel notification)
|
||||
public async Task<IActionResult> SendNotification([FromBody] FireBaseResponseModel notification)
|
||||
{
|
||||
var result = await FirebaseNotificationAppService.SendNotification(notification);
|
||||
// FcmTokenResponseModel results = JsonConvert.DeserializeObject<FcmTokenResponseModel>(result).ToJsonString();
|
||||
var result = await _notificationService.SendNotification(notification);
|
||||
return Ok(result.Responses);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> GetNotifications(NotificationModel notification)
|
||||
{
|
||||
var result = _notificationService.GetNotification(notification);
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user