/// <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); } }
/// <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); } }
/// <summary> /// 新的用户和消息关联信息 /// </summary> /// <param name="un"></param> private void NewUserNotification(Model.Entity.UserNotification un) { DbParameter[] commandParameters = new DbParameter[] { Data.DBHelper.CreateInDbParameter("@UserID", DbType.Int32, un.UserID), Data.DBHelper.CreateInDbParameter("@DeviceID", DbType.Int32, un.DeviceID), Data.DBHelper.CreateInDbParameter("@Type", DbType.Int32, un.Type), Data.DBHelper.CreateInDbParameter("@ObjectId", DbType.Int32, un.ObjectId), Data.DBHelper.CreateInDbParameter("@Get", DbType.Boolean, un.Get), Data.DBHelper.CreateInDbParameter("@Notification", DbType.Boolean, un.Notification), Data.DBHelper.CreateInDbParameter("@CreateTime", DbType.DateTime, un.CreateTime), Data.DBHelper.CreateInDbParameter("@UpdateTime", DbType.DateTime, un.UpdateTime) }; const string sql = "Insert into [UserNotification] ([UserID],[DeviceID],[Type],[ObjectId],[Get],[Notification],[CreateTime],[UpdateTime]) values(@UserID,@DeviceID,@Type,@ObjectId,@Get,@Notification,@CreateTime,@UpdateTime)\n select @@IDENTITY as UserNotificationId"; un.UserNotificationId = int.Parse(Data.DBHelper.GetInstance().ExecuteScalar(CommandType.Text, sql, commandParameters).ToString()); this.CleanNotificationTemp(un.UserID); }
/// <summary> /// 推送更新通知 /// </summary> /// <param name="deviceId">设备编号</param> /// <param name="type">类型</param> /// <param name="user">用户</param> public void Send(int deviceId, int type, Model.Entity.User user) { if (user == null) { return; } var un = new Model.Entity.UserNotification { UserID = user.UserID, DeviceID = deviceId, Type = 6, ObjectId = type, Get = false, CreateTime = DateTime.Now, UpdateTime = DateTime.Now, Notification = false }; this.NewUserNotification(un); }