Firebase Multiple Message C#
https://drive.google.com/drive/folders/1aCni1wSrVxI_HAPJSMQyL4NqVmyaB5Kp?usp=sharing
public IActionResult send()
{
var token = new List<string>(){ "cxTeC_oLTPm-dUx7NYOHWA:APA91bGr9UaN3r_oOGpK7lSMNBTQceVuJI4-ylct3n16HLE6bz037cCf9xbLuWECEkK0qOynZ7BqFRpAXTR7xI6I2Q--ia_qsmgSfHnGlov8XxmDjLirT7qpccYCnrdKMNNKYKc15_un",
"cTKCuKxv99_KfGeszSNK9e:APA91bHbRmsCCYPtYZjh8YWB48cUvuGQjzoDmFAbjGb9AymprrX7cbrY0G6FSkyGDpXkn9E6laqiPnTRcU95fks5Ssu5NbBntrurrBeOkZxAMHI_8mY34fi5bnrFufac6FWmTfQwuY7r",
"fwMSzFl_isuQRxpE-UqXkZ:APA91bHMzXypcPOWXK5mb6TlSV99F7BsSoKd_Ak9iI4AhkOJWf3Y42g_vtuv0n5J5hPvqm_-EQP4SYVHNb5LX9YV9qdPid5UMKoXFk2TTKjPmdAwegmrQZMqK0sTRStXatSQVqs-SA0-"};
SendNotificationMulti(token);
return Content("ok");
}
public void SendNotificationMulti(List<string> token)
{
WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send");
tRequest.Method = "post";
//serverKey - Key from Firebase cloud messaging server
tRequest.Headers.Add(string.Format("Authorization: key={0}", "AAAAJK69hmY:APA91bFIAlxCongUoFHwTvObduFKhi9KKdT0d7LII8290jcS0yTXAx170oes6bA89CzhSWowv3xBMlo6MzglNqVXYYa0IXsuy3G0CmoYjz-bxRNGTVdbbRmABoj9CUn7GcjO1fzHXUnU"));
//Sender Id - From firebase project setting
tRequest.Headers.Add(string.Format("Sender: id={0}", "157550478950"));
tRequest.ContentType = "application/json";
var payload = new
{
registration_ids = token,
priority = "high",
content_available = true,
notification = new
{
body = "notif firebase",
title = "SMS!",
badge = 2,
icon = "https://cdn.showtime.co.id/images_2/images/v2/Carousel-My-Showtime---Premium-Membership.jpg",
click_action = "https://myshowtime.world"
}
};
string postbody = JsonConvert.SerializeObject(payload).ToString();
Byte[] byteArray = Encoding.UTF8.GetBytes(postbody);
tRequest.ContentLength = byteArray.Length;
using (Stream dataStream = tRequest.GetRequestStream())
{
dataStream.Write(byteArray, 0, byteArray.Length);
using (WebResponse tResponse = tRequest.GetResponse())
{
using (Stream dataStreamResponse = tResponse.GetResponseStream())
{
if (dataStreamResponse != null) using (StreamReader tReader = new StreamReader(dataStreamResponse))
{
String sResponseFromServer = tReader.ReadToEnd();
//result.Response = sResponseFromServer;
}
}
}
}
}
Tidak ada komentar