示例#1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="content"></param>
        /// <param name="tenantId"></param>
        public static void SendMobileMessage(string content, int tenantId)
        {
            var userDeviceTokenList = GetUserDeviceTokenListByTenantId(tenantId);

            if (userDeviceTokenList.Any())
            {
                //Dictionary<int, Dictionary<string, int>> allUserDeviceToken = new Dictionary<int, Dictionary<string, int>>();
                //var userIds = userDeviceTokenList.Select(p => p.UserId).Distinct();
                //foreach (var uid in userIds)
                //{
                //    Dictionary<string, int> kv = new Dictionary<string, int>();
                //    var tmp = userDeviceTokenList.Where(p => p.UserId == uid);
                //    foreach (var item in tmp)
                //    {
                //        kv.Add(item.DeviceToken, item.Device);
                //    }
                //    allUserDeviceToken.Add(uid, kv);
                //}
                //MobileMessageInformation messageInfo = new MobileMessageInformation
                //{
                //    SendStatus = 0,
                //    AllMessageContent = content,
                //    AllUserDeviceToken = allUserDeviceToken
                //};
                //new RabbitMQHelper(Rabbit_MobileMessageAddress, Rabbit_userName, Rabbit_password, Rabbit_SendMobileMessage,
                //                   Rabbit_MobileMessagequeue).SendMessage(messageInfo);


                var list    = new List <MobileMessage>();
                var userIds = userDeviceTokenList.Select(p => p.UserId).Distinct();
                foreach (var uid in userIds)
                {
                    var userDeviceToken = new Dictionary <string, int[]>();
                    var tmp             = userDeviceTokenList.Where(p => p.UserId == uid);
                    foreach (var item in tmp)
                    {
                        userDeviceToken.Add(item.DeviceToken, new int[] { item.Device, item.NotSeeMessageCount + 1 });
                    }
                    list.Add(new MobileMessage
                    {
                        Content         = content,
                        UserDeviceToken = userDeviceToken,
                        UserId          = uid
                    });
                }

                _dataAccess.UpdateFieldCalc("Sys_UserDeviceToken", "NotSeeMessageCount", "NotSeeMessageCount + 1", "where RecordId in (" + userDeviceTokenList.Select(p => p.RecordId).GetString() + ")");

                MobileMessageInformation messageInfo = new MobileMessageInformation
                {
                    SendStatus = 1,
                    SendList   = list
                };

                RibbitMQProvider.SendMessage(messageInfo, "sendMobileMessage");
            }
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="content"></param>
        /// <param name="userCustomItems"></param>
        public static void SendMobileMessage(string content, Dictionary <int, Dictionary <string, object[]> > userCustomItems)
        {
            var userId = userCustomItems.Keys;
            //ios
            var userDeviceTokenList = GetUserDeviceTokenListByUserIds(userId);

            if (userDeviceTokenList.Count() > 0)
            {
                var list    = new List <MobileMessage>();
                var userIds = userDeviceTokenList.Select(p => p.UserId).Distinct();
                foreach (var uid in userIds)
                {
                    var userDeviceToken = new Dictionary <string, int[]>();
                    var tmp             = userDeviceTokenList.Where(p => p.UserId == uid);
                    foreach (var item in tmp)
                    {
                        userDeviceToken.Add(item.DeviceToken, new int[] { item.Device, item.NotSeeMessageCount + 1 });
                    }
                    list.Add(new MobileMessage
                    {
                        Content         = content,
                        CustomItems     = userCustomItems[uid],
                        UserDeviceToken = userDeviceToken,
                        UserId          = uid
                    });
                }

                _dataAccess.UpdateFieldCalc("Sys_UserDeviceToken", "NotSeeMessageCount", "NotSeeMessageCount + 1", "where RecordId in (" + userDeviceTokenList.Select(p => p.RecordId).GetString() + ")");

                MobileMessageInformation messageInfo = new MobileMessageInformation
                {
                    SendStatus = 1,
                    SendList   = list
                };
                RibbitMQProvider.SendMessage(messageInfo, "sendMobileMessage");
            }
            //Android
            var mobilemessagelist = new List <RetechWing.Models.Mobile.Sys_MobileMessage>();

            foreach (var item in userCustomItems)
            {
                mobilemessagelist.Add(new RetechWing.Models.Mobile.Sys_MobileMessage
                {
                    Content  = content,
                    UserId   = item.Key,
                    SendTime = DateTime.Now,
                    Status   = 0
                });
            }
            if (mobilemessagelist.Count > 0)
            {
                _dataAccess.AddEntities(mobilemessagelist);
            }
        }
示例#3
0
        /// <summary>
        /// 系统发送 站内信、邮件、短信
        /// </summary>
        /// <param name="title">标题</param>
        /// <param name="content">内容</param>
        /// <param name="recUserId">收件人</param>
        /// <param name="sendFlag">发送方式
        /// <para>0:站内信;</para>
        /// <para>1:邮件;</para>
        /// <para>2:短信;</para>
        /// <para>11:站内信、邮件;</para>
        /// <para>22:站内信、短信;</para>
        /// <para>33:邮件、短信;</para>
        /// <para>99:站内信、邮件、短信;</para>
        /// </param>
        /// <param name="tenantId"></param>
        public static void SendMessage(string title, string content, int[] recUserId, int sendFlag, int tenantId)
        {
            if (recUserId.Length == 0 || string.IsNullOrWhiteSpace(title) || string.IsNullOrWhiteSpace(content))
            {
                return;
            }
            if (sendFlag == 0 || sendFlag == 99 || sendFlag == 11 || sendFlag == 22)
            {
                //1:
                //SendUserMessage(title, content, recUserId, tenantId);
                //2:
                //new UserMessageManager().AddMessage(title, content, recUserId, 0, tenantId);
                //3:
                var messageContent = new SysUserMessageContent()
                {
                    Title          = title,
                    MessageContent = content,
                    CreateTime     = DateTime.Now,
                    TenantId       = tenantId
                };
                messageContent.MessageId = _dataAccess.AddEntity(messageContent);
                var list = new List <SysUserMessage>();
                for (int i = 0; i < recUserId.Length; i++)
                {
                    if (recUserId[i] > 0)
                    {
                        list.Add(new SysUserMessage
                        {
                            MessageId  = messageContent.MessageId,
                            SendStatus = 0,
                            RecStatus  = 0,
                            SendUserId = 0,
                            RecUserId  = recUserId[i],
                            TenantId   = tenantId
                        });
                    }
                }
                _dataAccess.AddEntities(list);
            }
            if (sendFlag == 1 || sendFlag == 99 || sendFlag == 11 || sendFlag == 33)
            {
                var userlist = GetUserList(recUserId);
                EmailInformation emailinf = new EmailInformation();
                emailinf.ToList   = userlist.Where(p => !string.IsNullOrWhiteSpace(p.Email)).Select(p => p.Email).ToList();
                emailinf.SendFlag = 1;
                emailinf.Subject  = title;
                //emailinf.mailName = mailName;
                //emailinf.Context = content.Replace("/[urllanguage]", "http://" + System.Web.HttpContext.Current.Request.Url.Authority);
                emailinf.Context  = content.Replace("/[urllanguage]", "");
                emailinf.UserName = Email_Username;
                if (System.Configuration.ConfigurationManager.AppSettings["ConfigEncrypt"] == "True")
                {
                    emailinf.PassWord = Extensions.EncryptHelper.Decrypto(Email_Password);
                }
                else
                {
                    emailinf.PassWord = Email_Password;
                }

                //接收邮件服务器
                emailinf.From = Email_From;
                //发送邮件服务器
                emailinf.Host = Email_Host;
                //端口
                emailinf.IPort = Convert.ToInt32(Email_IPort);

                RibbitMQProvider.SendMessage(emailinf, "sendEmail");
            }
            //if (sendFlag == 2 || sendFlag == 99 || sendFlag == 22 || sendFlag == 33)
            //;发送短信
        }
示例#4
0
        /// <summary>
        /// 系统发送 站内信、邮件、短信
        /// </summary>
        /// <param name="messageList"></param>
        /// <param name="sendFlag">发送方式
        /// <para>0:站内信;</para>
        /// <para>1:邮件;</para>
        /// <para>2:短信;</para>
        /// <para>11:站内信、邮件;</para>
        /// <para>22:站内信、短信;</para>
        /// <para>33:邮件、短信;</para>
        /// <para>99:站内信、邮件、短信;</para>
        /// </param>
        /// <param name="tenantId"></param>
        public static void SendMessage(List <SysIinstationMessage> messageList, int sendFlag, int tenantId)
        {
            if (messageList.Count == 0)
            {
                return;
            }
            if (sendFlag == 0 || sendFlag == 99 || sendFlag == 11 || sendFlag == 22)
            {
                //1:
                //SendUserMessage(messageList, tenantId);
                //2:
                //var userMessageManager = new UserMessageManager();
                //foreach (var item in messageList)
                //{
                //    userMessageManager.AddMessage(item.title, item.content, item.recUserId, 0, tenantId);
                //}
                //3:
                var list = new List <SysUserMessage>();
                foreach (var item in messageList)
                {
                    var messageContent = new SysUserMessageContent()
                    {
                        Title          = item.title,
                        MessageContent = item.content,
                        CreateTime     = DateTime.Now,
                        TenantId       = tenantId
                    };
                    messageContent.MessageId = _dataAccess.AddEntity(messageContent);
                    for (int i = 0; i < item.recUserId.Length; i++)
                    {
                        if (item.recUserId[i] > 0)
                        {
                            list.Add(new SysUserMessage
                            {
                                MessageId  = messageContent.MessageId,
                                SendStatus = 0,
                                RecStatus  = 0,
                                SendUserId = 0,
                                RecUserId  = item.recUserId[i],
                                TenantId   = tenantId
                            });
                        }
                    }
                }
                _dataAccess.AddEntities(list);
            }
            if (sendFlag == 1 || sendFlag == 99 || sendFlag == 11 || sendFlag == 33)
            {
                List <int> userIds = new List <int>();
                foreach (var item in messageList)
                {
                    userIds.AddRange(item.recUserId);
                }
                var userlist = GetUserList(userIds.Distinct());
                var ep       = Email_Password;
                if (System.Configuration.ConfigurationManager.AppSettings["ConfigEncrypt"] == "True")
                {
                    ep = Extensions.EncryptHelper.Decrypto(Email_Password);
                }

                //发送邮件
                foreach (var item in messageList)
                {
                    EmailInformation emailinf = new EmailInformation();
                    emailinf.ToList   = userlist.Where(p => item.recUserId.Contains(p.UserId) && (!string.IsNullOrWhiteSpace(p.Email))).Select(p => p.Email).ToList();
                    emailinf.SendFlag = 1;
                    emailinf.Subject  = item.title;
                    //emailinf.mailName = mailName;
                    emailinf.Context  = item.content.Replace("/[urllanguage]", "http://" + System.Web.HttpContext.Current.Request.Url.Authority + "/" + System.Threading.Thread.CurrentThread.CurrentCulture.ToString());
                    emailinf.UserName = Email_Username;
                    emailinf.PassWord = ep;
                    //接收邮件服务器
                    emailinf.From = Email_From;
                    //发送邮件服务器
                    emailinf.Host = Email_Host;
                    //端口
                    emailinf.IPort = Convert.ToInt32(Email_IPort);

                    RibbitMQProvider.SendMessage(emailinf, "sendEmail");
                }
            }
            //if (sendFlag == 2 || sendFlag == 99 || sendFlag == 22 || sendFlag == 33)
            //  ;发送短信
        }