public async Task <ActionResult <FCMResponse> > SendItemToAlert([FromBody] Pushrequest request) { string[] tokens = request.deviceToken.Split(','); if (request.categoryIdentifier == null || request.categoryIdentifier == "") { request.categoryIdentifier = "Chat"; } using (var client = new HttpClient()) { client.BaseAddress = new Uri("https://fcm.googleapis.com/"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "AAAA-uswhXo:APA91bE0fOLog-yLH5fS-ztQC6lgzyRKca2eYW9gTwUFE0YRyjTqDkfFwWMPwK5jAgKUUuKMogElIsZS9ePo0gfnTld8meMlRMFhuttPkTliu-lA0UvrsOgvN81KsnB211r3shu9c0n8OAh4y25xogyOdmjP7mYR6g"); client.DefaultRequestHeaders.Add("Sender", "id=1077687649658"); string objNotification = string.Empty; //android if (string.IsNullOrEmpty(request.title) && string.IsNullOrEmpty(request.data)) { objNotification = Newtonsoft.Json.JsonConvert.SerializeObject(new { registration_ids = tokens, content_available = true, categoryIdentifier = request.categoryIdentifier, priority = "high", click_action = request.data, }); } //ios else { objNotification = Newtonsoft.Json.JsonConvert.SerializeObject(new { registration_ids = tokens, priority = "high", notification = new { title = request.title, body = request.data, sound = "default", categoryIdentifier = request.categoryIdentifier, click_action = request.data, icon = request.image, }, }); } HttpResponseMessage response = await client.PostAsync("fcm/send", new StringContent(objNotification, Encoding.UTF8, "application/json")); if (response.IsSuccessStatusCode) { return(await response.Content.ReadAsAsync <FCMResponse>()); } return(null); } }
public dynamic fillAlert(dynamic item, string token) { Pushrequest productToAlert = new Pushrequest(); productToAlert.title = item.title[0]; productToAlert.deviceToken = token; productToAlert.data = item.viewItemURL[0];; productToAlert.image = item.galleryURL[0]; productToAlert.categoryIdentifier = "jgj"; return(productToAlert); }