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 StartKfMeeting() { if (!string.IsNullOrWhiteSpace(Token)) { if (Token != "ocean") { return(JsonHelper.AnalysisJson <string>("凭证错误", "error", null)); } } KfMeeting kfMeeting2 = _kfMeetingService.GetUnique(m => m.MpUserId == SendUserId && !m.IsEnd, "CreateDate", false); if (kfMeeting2 != null && kfMeeting2.KfNumberId != Guid.Empty) { string message2 = string.Empty; Log4NetImpl.Write("SendPrivateMessage:" + kfMeeting2.MpUserId.ToString(), kfMeeting2.KfNumberId.ToString()); new CommandManager(null).TryHandleCommand("SendPrivateMessage", new string[] { kfMeeting2.MpUserId.ToString(), kfMeeting2.KfNumberId.ToString(), "客服" }, ref message2); return(JsonHelper.AnalysisJson <string>("已经接入", "error", null)); } string message = string.Empty; IList <KfNumber> listKfNumber = _kfNumberService.GetALL().Where(m => m.IsOnline == true && m.OnlineStatus == 0).ToList(); if (listKfNumber.Count == 0) { //把消息发送给微信端客户 MpUser mpUser2 = _mpUserService.GetById(SendUserId); if (mpUser2 != null && !string.IsNullOrWhiteSpace(mpUser2.OpenID)) { _mpUserService.SendMessage(mpUser2.OpenID, "当前没有客服在线"); } return(JsonHelper.AnalysisJson <string>("当前没有客服在线", "error", null)); } var kfMeeting = new KfMeeting() { BeginDate = DateTime.Now, IsEnd = false, MpUserId = SendUserId }; _kfMeetingService.Insert(kfMeeting); //向所有在线客服发送接入请求 //访客名称 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, "等待客服接入,输入【退出】或【tc】退出聊天状态"); } } else { visitName = "访客_" + new Random().Next(100); } foreach (KfNumber model in listKfNumber) { new CommandManager(null).TryHandleCommand("Notice", new string[] { SendUserId.ToString(), visitName, model.Id.ToString(), "1", "0", kfMeeting.Id.ToString() }, ref message); } return(JsonHelper.AnalysisJson <string>(string.Empty, "ok", null)); }