Beispiel #1
0
        public void SendPush(string deviceToken, string msg)
        {
            var appDomain = System.AppDomain.CurrentDomain;
            string path = Path.Combine(appDomain.BaseDirectory, "Content", "LyrixPushServerCertificates.pfx");

            var payload = new NotificationPayload(deviceToken, msg, 1, "default");
            //payload1.AddCustom("CustomKey", "CustomValue");
            var notificationList = new List<NotificationPayload> { payload };
            var push = new PushNotification(true, path, "123");
            var rejected = push.SendToApple(notificationList);
        }
Beispiel #2
0
        public void Challenge(string deviceToken, Guid code, string fromUserFbName)
        {
            if (deviceToken.Length != 64) return;
            string msg = fromUserFbName + " has challenged you to a Lyrix Game.";

            var appDomain = System.AppDomain.CurrentDomain;
            string path = Path.Combine(appDomain.BaseDirectory, "Content", "LyrixPushServerCertificates.pfx");

            var payload = new NotificationPayload(deviceToken, msg, 1, "default");
            payload.AddCustom("chKey", code.ToString());
            payload.AddCustom("FromFbName", fromUserFbName);
            var notificationList = new List<NotificationPayload> { payload };
            var push = new PushNotification(true, path, "123");
            var rejected = push.SendToApple(notificationList);
        }
Beispiel #3
0
        public void SendTestPush(string deviceToken, string msg)
        {
            if(deviceToken.Length != 64)
            {
                deviceToken = "a619b266b4b3c384f7072493a67d71a9da71121ecf1cfcc6dc6f963c39d05603";
            }

            if(string.IsNullOrEmpty(msg))
            {
                msg = "Why null string dude?";
            }

            //string path = "LyrixPushServerCertificates.p12";
            //string path = Path.Combine(GetApplicationFolder(), @"E:\Projects\Lyrix\ApnsServices\Certificates\LyrixPushServerCertificates.p12");

            var appDomain = System.AppDomain.CurrentDomain;
            string path = Path.Combine(appDomain.BaseDirectory, "Content", "LyrixPushServerCertificates.pfx");

            var payload = new NotificationPayload(deviceToken, msg, 1, "default");
            //payload1.AddCustom("CustomKey", "CustomValue");
            var notificationList = new List<NotificationPayload> { payload };
            var push = new PushNotification(true, path, "123");
            var rejected = push.SendToApple(notificationList);
        }
Beispiel #4
0
        private static byte[] GeneratePayload(NotificationPayload payload)
        {
            try
            {
                //convert Devide token to HEX value.
                byte[] deviceToken = new byte[payload.DeviceToken.Length / 2];
                for (int i = 0; i < deviceToken.Length; i++)
                    deviceToken[i] = byte.Parse(payload.DeviceToken.Substring(i * 2, 2), System.Globalization.NumberStyles.HexNumber);

                var memoryStream = new MemoryStream();

                // Command
                memoryStream.WriteByte(1); // Changed command Type

                //Adding ID to Payload
                memoryStream.Write(Encoding.ASCII.GetBytes(payload.PayloadId.ToString()), 0, payload.PayloadId.ToString().Length);

                //Adding ExpiryDate to Payload
                int epoch = (int)(DateTime.UtcNow.AddMinutes(300) - new DateTime(1970, 1, 1)).TotalSeconds;
                byte[] timeStamp = BitConverter.GetBytes(epoch);
                memoryStream.Write(timeStamp, 0, timeStamp.Length);

                byte[] tokenLength = BitConverter.GetBytes((Int16)32);
                Array.Reverse(tokenLength);
                // device token length
                memoryStream.Write(tokenLength, 0, 2);

                // Token
                memoryStream.Write(deviceToken, 0, 32);

                // String length
                string apnMessage = payload.ToJson();

                byte[] apnMessageLength = BitConverter.GetBytes((Int16)apnMessage.Length);
                Array.Reverse(apnMessageLength);

                // message length
                memoryStream.Write(apnMessageLength, 0, 2);

                // Write the message
                memoryStream.Write(Encoding.ASCII.GetBytes(apnMessage), 0, apnMessage.Length);
                return memoryStream.ToArray();
            }
            catch (Exception ex)
            {
                return null;
            }
        }