/// <summary> /// 发送消息 ,服务器接收的是CSChatMessage实体,他包含发送人,接收人,消息内容等信息 /// </summary> /// <param name="msg"></param> /// <returns></returns> public Task ClientSendMsgToClient(AchieveEntity.CSChatMessage msg) { var groupName = MessageUtils.GetGroupName(msg.fromuser.userid.ToString(), msg.touser.userid.ToString()); /* * 中间处理一下消息直接转发给(A,B所在组织,即聊天窗口) */ msg.other = new { t = "one" }; msg.msgtype = AchieveEntity.CSMessageType.Custom;//消息类型为普通消息 //添加消息记录 Sys_Chatrecord cd = new Sys_Chatrecord(); cd.F_Id = System.Guid.NewGuid().ToString(); cd.F_Type = 1; cd.F_SendId = msg.fromuser.userid.ToString(); cd.F_Message = msg.msg; cd.F_AcceptId = msg.touser.userid.ToString(); cd.F_CreatorTime = DateTime.Now; cd.F_CreatorUserId = OperatorProvider.Provider.GetCurrent().UserCode; new Sys_LayimBLL().AddChatrecord(cd); return(Clients.Group(groupName).receiveMessage(msg)); }
/// <summary> /// 发送消息 (群组),服务器接收的是CSChatMessage实体,他包含发送人,接收人,消息内容等信息 /// </summary> /// <param name="msg"></param> /// <returns></returns> public Task ClientSendMsgToGroup(AchieveEntity.CSChatMessage msg) { //获取要推送的组织名称 var groupName = MessageUtils.GetGroupName(msg.touser.userid.ToString()); //附加信息,为群信息 msg.other = new { t = "group" }; //普通信息类型 msg.msgtype = AchieveEntity.CSMessageType.Custom; //添加消息记录 Sys_Chatrecord cd = new Sys_Chatrecord(); cd.F_Id = System.Guid.NewGuid().ToString(); cd.F_Type = 2; cd.F_SendId = msg.fromuser.userid.ToString(); cd.F_Message = msg.msg; cd.F_AcceptId = msg.touser.userid.ToString(); cd.F_CreatorTime = DateTime.Now; cd.F_CreatorUserId = OperatorProvider.Provider.GetCurrent().UserCode; new Sys_LayimBLL().AddChatrecord(cd); return(Clients.Group(groupName).receiveMessage(msg)); }