BMC: Set FCMTokent In Body
This commit is contained in:
parent
6ef253f537
commit
f822cc9fe9
@ -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; }
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
|
||||
var message = new MulticastMessage()
|
||||
{
|
||||
Notification = notification,
|
||||
Token = fcmToken,
|
||||
Notification = notification.notification,
|
||||
Tokens = notification.FcmToken,
|
||||
};
|
||||
|
||||
return await FirebaseMessaging.DefaultInstance.SendAsync(message) ;
|
||||
|
||||
var response = await FirebaseMessaging.DefaultInstance.SendMulticastAsync(message);
|
||||
return response;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
|
@ -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; }
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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…
x
Reference in New Issue
Block a user