public string ReceptionKfMeeting() { KfMeeting kfMeeting = _kfMeetingService.GetById(KfMeetingId); if (kfMeeting.IsEnd) { return(JsonHelper.AnalysisJson <string>("当前会话已被对方结束", "error", null)); } kfMeeting.BeginDate = DateTime.Now; kfMeeting.KfNumberId = KfNumberId; _kfMeetingService.Update(kfMeeting); //向其他客服发送当前客户已经接管的通知 string message = string.Empty; IList <KfNumber> listKfNumber = _kfNumberService.GetALL().Where(m => m.Id != KfNumberId && m.IsOnline == true).ToList(); foreach (KfNumber model in listKfNumber) { new CommandManager(null).TryHandleCommand("Notice", new string[] { KfNumberId.ToString(), "客服接入", model.Id.ToString(), "2", "0", kfMeeting.MpUserId.ToString() }, ref message); } //向用户发送已经接入成功的消息 string message2 = string.Empty; new CommandManager(null).TryHandleCommand("SendPrivateMessage", new string[] { KfNumberId.ToString(), kfMeeting.MpUserId.ToString(), "接入成功,现在可以与客服对话了" }, ref message2); //把消息发送给微信端客户 MpUser mpUser = _mpUserService.GetById(kfMeeting.MpUserId); if (mpUser != null && !string.IsNullOrWhiteSpace(mpUser.OpenID)) { _mpUserService.SendMessage(mpUser.OpenID, "接入成功,现在可以与客服对话了"); } //更新用户状态 _mpUserService.ChangeMpUserState(kfMeeting.MpUserId, 1); return(JsonHelper.AnalysisJson <string>(string.Empty, "ok", null)); }
public string EndKfMeeting() { if (!string.IsNullOrWhiteSpace(Token)) { if (Token != "ocean") { return(JsonHelper.AnalysisJson <string>("凭证错误", "error", null)); } } KfMeeting kfMeeting = _kfMeetingService.GetById(KfMeetingId); if (!kfMeeting.IsEnd) { kfMeeting.RecordCount = _kfMeetingMessageService.GetCount(" where KfMeetingId='" + kfMeeting.Id + "'"); kfMeeting.EndDate = DateTime.Now; kfMeeting.IsEnd = true; _kfMeetingService.Update(kfMeeting); //向客服发送断开通知 string message = string.Empty; //访客名称 string visitName = string.Empty; MpUser mpUser = _mpUserService.GetById(kfMeeting.MpUserId); if (mpUser != null) { visitName = mpUser.NickName; if (!string.IsNullOrWhiteSpace(mpUser.OpenID)) { _mpUserService.SendMessage(mpUser.OpenID, "成功退出聊天,输入【客服】或【kf】转人工客服"); } } else { visitName = "访客_" + new Random().Next(100); } new CommandManager(null).TryHandleCommand("Notice", new string[] { kfMeeting.MpUserId.ToString(), visitName, kfMeeting.KfNumberId.ToString(), "3", "0", kfMeeting.MpUserId.ToString() }, ref message); //断开当前用户的所有连接 _kfMeetingService.ExcuteSql("update KfMeeting set IsEnd=1 where MpUserId='" + kfMeeting.MpUserId + "'"); } //更新用户状态 _mpUserService.ChangeMpUserState(kfMeeting.MpUserId, 0); return(JsonHelper.AnalysisJson <string>(string.Empty, "ok", null)); }
public override void ExecuteNotice(CallerContext callerContext, string[] args, ref string message) { int type = int.Parse(args[1]); //客服离线 if (type == 1) { Guid kfNumberId = new Guid(args[0]); //移除缓存中的客服 MessageManager.Instance.RemoveCacheKF(kfNumberId); //离线时清理线程中的客服端(防止第一条离线信息丢失) CometThreadPool.DequeueCometWaitRequest(kfNumberId); //断开与所有访客的会话 IKfNumberService kfNumberService = EngineContext.Current.Resolve <IKfNumberService>(); IKfMeetingService kfMeetingService = EngineContext.Current.Resolve <IKfMeetingService>(); IKfMeetingMessageService kfMeetingMessageService = EngineContext.Current.Resolve <IKfMeetingMessageService>(); IMpUserService mpUserService = EngineContext.Current.Resolve <IMpUserService>(); IList <KfMeeting> listMeeting = kfMeetingService.GetALL().Where(m => m.KfNumberId == kfNumberId && m.IsEnd == false).ToList(); foreach (KfMeeting kfMeeting in listMeeting) { kfMeeting.RecordCount = kfMeetingMessageService.GetCount(" where KfMeetingId='" + kfMeeting.Id + "'"); kfMeeting.EndDate = DateTime.Now; kfMeeting.IsEnd = true; kfMeetingService.Update(kfMeeting); base.SendPrivateMessage(kfNumberId, kfMeeting.MpUserId, "本次会话已被断开,您可以重新发起会话请求"); //发送给微信 MpUser mpUser = mpUserService.GetById(kfMeeting.MpUserId); if (mpUser != null && !string.IsNullOrWhiteSpace(mpUser.OpenID)) { mpUserService.SendMessage(mpUser.OpenID, "本次会话已被断开,您可以重新发起会话请求"); } //更新用户状态 mpUserService.ChangeMpUserState(kfMeeting.MpUserId, 0); } //把客服设置成离线 KfNumber kfNumber = kfNumberService.GetById(kfNumberId); kfNumber.IsOnline = false; kfNumberService.Update(kfNumber); } //访客离线 if (type == 2) { Guid mpUserId = new Guid(args[0]); //离线时清理线程中的访客端(防止第一条离线信息丢失) CometThreadPool.DequeueCometWaitRequest(mpUserId); //断开与客服的会话 IKfMeetingService kfMeetingService = EngineContext.Current.Resolve <IKfMeetingService>(); IKfMeetingMessageService kfMeetingMessageService = EngineContext.Current.Resolve <IKfMeetingMessageService>(); IList <KfMeeting> listMeeting = kfMeetingService.GetALL().Where(m => m.MpUserId == mpUserId && m.IsEnd == false).ToList(); foreach (KfMeeting kfMeeting in listMeeting) { kfMeeting.RecordCount = kfMeetingMessageService.GetCount(" where KfMeetingId='" + kfMeeting.Id + "'"); kfMeeting.EndDate = DateTime.Now; kfMeeting.IsEnd = true; kfMeetingService.Update(kfMeeting); base.SendNotice(mpUserId, "访客_" + new Random().Next(100), kfMeeting.KfNumberId, 3, 0, mpUserId.ToString()); } } }