Browse Source

BMC: Set FCMTokent In Body

feature/ModificationForSentNotificationAPI
Palash Biswas 2 years ago
parent
commit
f822cc9fe9
4 changed files with 47 additions and 18 deletions
  1. +4
    -5
      BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/FirebaseResponseModel.cs
  2. +12
    -9
      BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/FirebaseNotificationAppService.cs
  3. +22
    -0
      BCS.BMC/src/BCS.BMC.Web.Core/Models/TokenAuth/FcmTokenResponseModel.cs
  4. +9
    -4
      BCS.BMC/src/BCS.BMC.Web.Mvc/Controllers/FirebaseNotificationController.cs

+ 4
- 5
BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/FirebaseResponseModel.cs View File

@ -1,4 +1,5 @@
using Newtonsoft.Json;
using FirebaseAdmin.Messaging;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
@ -9,9 +10,7 @@ namespace BCS.BMC.FirebaseCloudMessaging.Dto
{
public class FireBaseResponseModel
{
[JsonProperty("isSuccess")]
public bool IsSuccess { get; set; }
[JsonProperty("message")]
public string Message { get; set; }
public Notification notification { get; set; }
public List<string> FcmToken { get; set; }
}
}

+ 12
- 9
BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/FirebaseNotificationAppService.cs View File

@ -3,7 +3,9 @@ using System.Threading.Tasks;
using FirebaseAdmin;
using Google.Apis.Auth.OAuth2;
using System;
using BCS.BMC.FirebaseCloudMessaging.Dto;
using System.Collections.Generic;
using Abp.Json;
namespace BCS.BMC.FirebaseCloudMessaging
{
@ -22,18 +24,19 @@ namespace BCS.BMC.FirebaseCloudMessaging
}
public static async Task<string> SendNotification(string fcmToken, Notification notification)
public static async Task<BatchResponse> SendNotification( FireBaseResponseModel notification)
{
try
{
var message = new Message()
{
Notification = notification,
Token = fcmToken,
};
var message = new MulticastMessage()
{
Notification = notification.notification,
Tokens = notification.FcmToken,
};
return await FirebaseMessaging.DefaultInstance.SendAsync(message) ;
var response = await FirebaseMessaging.DefaultInstance.SendMulticastAsync(message);
return response;
}
catch(Exception ex)
{


+ 22
- 0
BCS.BMC/src/BCS.BMC.Web.Core/Models/TokenAuth/FcmTokenResponseModel.cs View File

@ -0,0 +1,22 @@
using FirebaseAdmin.Messaging;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BCS.BMC.Models.TokenAuth
{
public class FcmTokenResponseModel
{
public result results { get; set; }
}
public class results
{
public string message { get; set; }
}
}

+ 9
- 4
BCS.BMC/src/BCS.BMC.Web.Mvc/Controllers/FirebaseNotificationController.cs View File

@ -1,7 +1,11 @@
using BCS.BMC.Controllers;
using Abp.Json;
using BCS.BMC.Controllers;
using BCS.BMC.FirebaseCloudMessaging;
using BCS.BMC.FirebaseCloudMessaging.Dto;
using BCS.BMC.Models.TokenAuth;
using FirebaseAdmin.Messaging;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Threading.Tasks;
@ -20,10 +24,11 @@ namespace BCS.BMC.Web.Controllers
[Route("send")]
[HttpPost]
public async Task<IActionResult> Notification(string fcmToken, [FromBody] Notification notification)
public async Task<IActionResult> Notification( [FromBody] FireBaseResponseModel notification)
{
var result = await FirebaseNotificationAppService.SendNotification(fcmToken, notification);
return Ok(result);
var result = await FirebaseNotificationAppService.SendNotification(notification);
// FcmTokenResponseModel results = JsonConvert.DeserializeObject<FcmTokenResponseModel>(result).ToJsonString();
return Ok(result.Responses);
}
}
}

Loading…
Cancel
Save