//public async Task<int> UpdateNotification(AndroidToken notificationToken) //{ // var query = @"UPDATE [dbo].[AndroidToken] // SET[UpdatedAt] = @UpdatedAt // ,[CompanyId] = @CompanyId // ,[UserId] = @UserId // WHERE [Id] = @Id"; // notificationToken.UpdatedAt = DateTime.UtcNow; // using (IDbConnection conn = Connection) // { // conn.Open(); // return await conn.ExecuteAsync(query.ToString(), // new // { // notificationToken.UpdatedAt, // notificationToken.CompanyId, // notificationToken.UserId, // notificationToken.Id // }); // } //} public async Task <int> UpdateNotification(IOSToken iOSToken) { iOSToken.UpdatedAt = DateTime.UtcNow; var query = @"UPDATE [dbo].[IOSToken] SET [UpdatedAt] = @UpdatedAt ,[DeletedAt] = @DeletedAt WHERE [Id] = @Id AND [CompanyId] = @CompanyId AND [UserId] = @UserId"; using (IDbConnection conn = Connection) { conn.Open(); return(await conn.ExecuteAsync(query.ToString(), new { iOSToken.UpdatedAt, iOSToken.DeletedAt, iOSToken.Id, iOSToken.CompanyId, iOSToken.UserId, })); } }
public async Task <int> CreateNotification(IOSToken iOSToken) { var query = @"INSERT Into [dbo].[IOSToken] ([Id], [CreatedAt], [CompanyId], [UserId]) Values(@Id, @CreatedAt, @CompanyId, @UserId)"; iOSToken.CreatedAt = DateTime.UtcNow; using (IDbConnection conn = Connection) { conn.Open(); return(await conn.ExecuteAsync(query.ToString(), new { iOSToken.Id, iOSToken.CreatedAt, iOSToken.CompanyId, iOSToken.UserId })); } }
private async Task SendPushIOSAsync(IOSNotification iOSNotification, Notification notification, IOSToken iOSToken, object data, Microsoft.Azure.WebJobs.ExecutionContext context) { int port = 2195; string hostname = "gateway.sandbox.push.apple.com"; var certificatePath = Path.GetFullPath(Path.Combine(context.FunctionDirectory, "..\\Files\\test.txt")); var lol = System.IO.File.ReadAllBytes(certificatePath); X509Certificate2 clientCertificate = new X509Certificate2(System.IO.File.ReadAllBytes(certificatePath), "YOUR_PASSWORD"); X509Certificate2Collection certificatesCollection = new X509Certificate2Collection(clientCertificate); TcpClient client = new TcpClient(AddressFamily.InterNetwork); await client.ConnectAsync(hostname, port); SslStream sslStream = new SslStream( client.GetStream(), false, new RemoteCertificateValidationCallback(ValidateServerCertificate), null); try { await sslStream.AuthenticateAsClientAsync(hostname, certificatesCollection, SslProtocols.Tls, false); MemoryStream memoryStream = new MemoryStream(); BinaryWriter writer = new BinaryWriter(memoryStream); writer.Write((byte)0); writer.Write((byte)0); writer.Write((byte)32); writer.Write(HexStringToByteArray(iOSToken.Id.ToUpper())); string payload = "{\"aps\":{\"alert\":\"" + notification.Message + "\",\"badge\":0,\"sound\":\"default\"}}"; writer.Write((byte)0); writer.Write((byte)payload.Length); byte[] b1 = System.Text.Encoding.UTF8.GetBytes(payload); writer.Write(b1); writer.Flush(); byte[] array = memoryStream.ToArray(); sslStream.Write(array); sslStream.Flush(); client.Dispose(); } catch (AuthenticationException ex) { client.Dispose(); } catch (Exception e) { client.Dispose(); } }