Exemple #1
0
        /// <summary>
        /// 推送系统消息
        /// </summary>
        /// <param name="notification">消息</param>
        /// <param name="user">用户</param>
        public void Send(Model.Entity.Notification notification, Model.Entity.User user)
        {
            if (notification.NotificationID == 0)
            {
                this.Save(notification);
            }

            if (user == null)
            {
                return;
            }

            var un = new Model.Entity.UserNotification
            {
                UserID       = user.UserID,
                DeviceID     = notification.DeviceID,
                Type         = notification.DeviceID == 0 ? 5 : 1,
                ObjectId     = notification.NotificationID,
                Get          = false,
                CreateTime   = DateTime.Now,
                UpdateTime   = DateTime.Now,
                Notification = false
            };

            this.NewUserNotification(un);
            return;

#pragma warning disable CS0162 // 检测到无法访问的代码
            if (user.LoginType == 2 && !string.IsNullOrEmpty(user.AppID) && user.AppID.Length == 64 && user.Notification)
#pragma warning restore CS0162 // 检测到无法访问的代码
            {
                var getList  = Logic.Notification.GetInstance().GetNotificationCount(user.UserID);
                var getTotal = getList.Sum(s => s.Message + s.Voice + s.SMS + s.Photo);
                YW.Notification.Notification alert = new YW.Notification.Notification(user.AppID);
                alert.Payload.Alert.Body = GetNotificationDescription(notification.Type,
                                                                      notification);
                if (user.NotificationSound)
                {
                    alert.Payload.Sound = "default";
                }
                alert.Payload.CustomItems.Add("Content",
                                              new object[]
                {
                    notification.Type, notification.DeviceID, notification.Content
                });
                alert.UserNotification = un;
                alert.Tag           = notification;
                alert.Payload.Badge = getTotal;
                this.GetServer(user.Project).QueueNotification(alert);
            }
        }
Exemple #2
0
        private void service_NotificationSuccess(object sender, YW.Notification.Notification notification)
        {
            //如果是绑定相关,则不设置成推送成功
            if (notification.UserNotification.Type == 1)
            {
                Model.Entity.Notification item = (Model.Entity.Notification)notification.Tag;
                if (item.Type == 2 || item.Type == 3 || item.Type == 4 || item.Type == 9)
                {
                    return;
                }
            }

            UpdateUserNotificationStatus(notification.UserNotification.UserID, notification.UserNotification.UserNotificationId, true);
            Console.WriteLine(string.Format("Notification Success: {0}", notification.ToString()));
        }
Exemple #3
0
        /// <summary>
        /// 推送语音信息
        /// </summary>
        /// <param name="voice">语音</param>
        /// <param name="user">用户</param>
        public void Send(Model.Entity.DeviceVoice voice, Model.Entity.User user)
        {
            if (user == null || voice == null)
            {
                return;
            }

            Model.Entity.UserNotification un = new Model.Entity.UserNotification
            {
                UserID       = user.UserID,
                Type         = 2,
                DeviceID     = voice.DeviceID,
                ObjectId     = voice.DeviceVoiceId,
                Get          = false,
                CreateTime   = DateTime.Now,
                UpdateTime   = DateTime.Now,
                Notification = false
            };
            if (voice.Type == 3 && user.UserID == voice.ObjectId) //如果是自己发的,则不通知自己
            {
                un.Notification = true;
            }
            this.NewUserNotification(un);
            return;

#pragma warning disable CS0162 // 检测到无法访问的代码
            if (!un.Notification && user.LoginType == 2 && !string.IsNullOrEmpty(user.AppID) && user.AppID.Length == 64 && user.Notification)
#pragma warning restore CS0162 // 检测到无法访问的代码
            {
                var getList  = Logic.Notification.GetInstance().GetNotificationCount(user.UserID);
                var getTotal = getList.Sum(s => s.Message + s.Voice + s.SMS + s.Photo);
                YW.Notification.Notification alert = new YW.Notification.Notification(user.AppID);
                alert.Payload.Alert.Body = GetNotificationDescription(1, voice);
                if (user.NotificationSound)
                {
                    alert.Payload.Sound = "default";
                }
                alert.Payload.CustomItems.Add("Content",
                                              new object[] { 1, voice.DeviceID, "" });

                alert.UserNotification = un;
                alert.Payload.Badge    = getTotal;
                this.GetServer(user.Project).QueueNotification(alert);
            }
        }
Exemple #4
0
 private void service_NotificationFailed(object sender, YW.Notification.Notification notification)
 {
     UpdateUserNotificationStatus(notification.UserNotification.UserID, notification.UserNotification.UserNotificationId, false);
     Console.WriteLine(string.Format("Notification Failed: {0}", notification.ToString()));
 }