Beispiel #1
0
        public ApiResult <SendMessageResponse> Send(string groupId, string imUserId, string msgType, string msgContent, string deviceType, string sourceType)
        {
            var response = new SendMessageResponse();

            if (groupId.IsNullOrEmpty())
            {
                return(Error <SendMessageResponse>("1", "组标识不能为空"));
            }

            if (imUserId.IsNullOrEmpty())
            {
                return(Error <SendMessageResponse>("2", "用户不能为空"));
            }

            var channelId = _groupInfoService.GetChannelId(groupId.ToGuid());

            if (channelId.IsNotNullOrEmpty())
            {
                var lasttime = DateTime.Now.ToUnix();
                var data     = NewsTypeHelper.ToChat(imUserId, sourceType, msgContent, lasttime);
                RedisHelper.Publish(channelId, data);
                _channelMessageService.Add(channelId, imUserId, msgType, msgContent, deviceType, sourceType, RequestHelper.Ip, "", lasttime);
            }

            return(Success(response));
        }
Beispiel #2
0
        public ApiResult <SendMessageResponse> Send(SendGroupMessageRequest request)
        {
            var response = new SendMessageResponse();

            if (request == null)
            {
                return(Error <SendMessageResponse>("1", "参数无能为空"));
            }

            if (request.GroupId.IsNullOrEmpty())
            {
                return(Error <SendMessageResponse>("2", "组标识不能为空"));
            }

            var channelId = _groupInfoService.GetChannelId(request.GroupId.ToGuid());

            if (channelId.IsNotNullOrEmpty())
            {
                var lasttime = DateTime.Now.ToUnix();
                var data     = NewsTypeHelper.ToChat(request.ImUserId, request.SourceType, request.MsgContent, lasttime);
                RedisHelper.Publish(channelId, data);
                _channelMessageService.Add(channelId, request.ImUserId, request.MsgType, request.MsgContent, request.DeviceType, request.SourceType, RequestHelper.Ip, "", lasttime);
            }
            return(Success(response));
        }
        public ApiResult <SendMessageResponse> Send(string channelId, string imUserId, string msgType, string msgContent, string deviceType, string sourceType)
        {
            var response = new SendMessageResponse();
            var lasttime = DateTime.Now.ToUnix();
            var data     = NewsTypeHelper.ToChat(imUserId, sourceType, msgContent, lasttime);

            RedisHelper.Publish(channelId, data);
            _channelMessageService.Add(channelId, imUserId, msgType, msgContent, deviceType, sourceType, RequestHelper.Ip, "", lasttime);
            return(Success(response));
        }
        public ApiResult <SendMessageResponse> Send(SendMessageRequest request)
        {
            var response = new SendMessageResponse();

            var lasttime = DateTime.Now.ToUnix();
            var data     = NewsTypeHelper.ToChat(request.ImUserId, request.SourceType, request.MsgContent, lasttime);

            RedisHelper.Publish(request.ChannelId, data);
            _channelMessageService.Add(request.ChannelId, request.ImUserId, request.MsgType, request.MsgContent, request.DeviceType, request.SourceType, RequestHelper.Ip, "", lasttime);
            return(Success(response));
        }
Beispiel #5
0
        /// <summary>
        /// 发送中断时的消息
        /// </summary>
        /// <param name="cm"></param>
        private void SendSuspendMsg(ChatManager cm)
        {
            if (string.IsNullOrEmpty(_lasttime))
            {
                return;
            }
            long lasttime;

            if (long.TryParse(_lasttime, out lasttime))
            {
                //查询是否有中断消息
                var channelMessageList = _channelMessageService.Query(cm.ChannelId.ToGuid(), lasttime);
                if (channelMessageList.Count > 0)
                {
                    foreach (var item in channelMessageList)
                    {
                        cm.SendMessage(NewsTypeHelper.ToChat(item.ImUserId.ToString(), _sourcetype, item.MsgContent, item.Timestamp));
                        Thread.Sleep(100);
                    }
                }
            }
        }