public NotificationCenter ConvertFromCustomNotificationToOrigin(FCMNotificationCenter fcm) { NotificationCenter result = new NotificationCenter { GroupId = fcm.GroupId, DeviceId = fcm.DeviceId, Content = fcm.Content, CreatedBy = fcm.CreatedBy, CreatedOn = fcm.CreatedOn, HaveSeen = fcm.HaveSeen, ReceivedUserId = fcm.ReceivedUserId, RecordId = fcm.RecordId, RecordNumber = fcm.RecordNumber, RelateRecordId = fcm.RelateRecordId, SubRelateRecordId = fcm.SubRelateRecordId, Title = fcm.Title, Type = fcm.Type, Id = fcm.Id }; return(result); }
public FCMPushNotification SendNotification(FCMNotificationCenter notificationcenter, string _clientId) { FCMPushNotification result = new FCMPushNotification(); try { result.Successful = true; result.Error = null; // var value = message; var requestUri = "https://fcm.googleapis.com/fcm/send"; WebRequest webRequest = WebRequest.Create(requestUri); webRequest.Method = "POST"; webRequest.Headers.Add(string.Format("Authorization: key={0}", "AAAAZVqqKsI:APA91bHD5xaB8tdiiUvRF0qTN-PAfp6FBKUCOl9H_rAdLD4j0ii29HMFY7H9XZgehDdE2KaiDneXvsQygJl3BFEUWsxgPHmyux0JwkSPYn2DGYUlMt_fNflu0_pbLNdMlbzLi76ALRLH")); webRequest.Headers.Add(string.Format("Sender: id={0}", "AIzaSyDMEeOtCPk7uIdl8V_t5XUkL78AfGqYXmM")); webRequest.ContentType = "application/json"; var data = new { to = _clientId, data = new FCMNotificationCenter { Title = notificationcenter.Title, Content = notificationcenter.Content, Type = notificationcenter.Type, FullName = notificationcenter.FullName, Avatar = notificationcenter.Avatar, RecordId = notificationcenter.RecordId, RelateRecordId = notificationcenter.RelateRecordId, SubRelateRecordId = notificationcenter.SubRelateRecordId, RecordNumber = notificationcenter.RecordNumber, CreatedOn = DateTime.Now, CreatedBy = notificationcenter.CreatedBy, HaveSeen = true, Id = notificationcenter.Id } }; var camelCaseFormatter = new JsonSerializerSettings(); camelCaseFormatter.ContractResolver = new CamelCasePropertyNamesContractResolver(); var json = JsonConvert.SerializeObject(data, camelCaseFormatter); Byte[] byteArray = Encoding.UTF8.GetBytes(json); webRequest.ContentLength = byteArray.Length; using (Stream dataStream = webRequest.GetRequestStream()) { dataStream.Write(byteArray, 0, byteArray.Length); using (WebResponse webResponse = webRequest.GetResponse()) { using (Stream dataStreamResponse = webResponse.GetResponseStream()) { using (StreamReader tReader = new StreamReader(dataStreamResponse)) { String sResponseFromServer = tReader.ReadToEnd(); result.Response = sResponseFromServer; } } } } } catch (Exception ex) { result.Successful = false; result.Response = null; result.Error = ex; } return(result); }