public string EndKfMeeting() { 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 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, "本次会话已被断开"); } //断开当前用户的所有连接 _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 string SendPrivateMessage() { try { KfNumber kfNumber = _kfNumberService.GetById(KfNumberId); if (kfNumber == null) { return(JsonHelper.AnalysisJson <string>("KfNumber对象为null", "error", null)); } KfMeeting kfMeeting = _kfMeetingService.GetById(KfMeetingId); if (kfMeeting.IsEnd) { return(JsonHelper.AnalysisJson <string>(string.Format("本条消息发送失败[{0}]", "本次会话已经结束"), "error", null)); } string messageText = Request["messageText"]; if (string.IsNullOrWhiteSpace(messageText)) { return(JsonHelper.AnalysisJson <string>("消息不能为空", "error", null)); } messageText = messageText.Trim(); // 防止XSS攻击 //messageText = Sanitizer.GetSafeHtmlFragment(messageText); //messageText = HttpUtility.HtmlEncode(StringHelper.StripHtml(messageText)); messageText = HttpUtility.HtmlEncode(messageText); //把消息存入数据库 //ICommunicationRepository iCommunicationRepository = new PersistedRepository(); _kfMeetingMessageService.InsertKfMeetingMessage(KfMeetingId, 1, messageText); //把消息发送给微信端客户 MpUser mpUser = _mpUserService.GetById(ReceiveUserId); if (mpUser != null && !string.IsNullOrWhiteSpace(mpUser.OpenID)) { _mpUserService.SendMessage(mpUser.OpenID, messageText); } //把消息发给通信线程进行中转(适用于web聊天) string message2 = string.Empty; if (new CommandManager(null).TryHandleCommand("SendPrivateMessage", new string[] { KfNumberId.ToString(), ReceiveUserId.ToString(), messageText }, ref message2) && string.IsNullOrWhiteSpace(message2)) { return(JsonHelper.AnalysisJson <string>(string.Empty, "ok", null)); } this.log.Warn(string.Format("消息发送失败,{0}", message2)); return(JsonHelper.AnalysisJson <string>(string.Format("本条消息发送失败[{0}]", message2), "error", null)); } catch (Exception ex) { this.log.Warn(ex.Message); return(JsonHelper.AnalysisJson <string>(string.Format("本条消息发送失败[{0}]", ex.Message), "error", null)); } }
public string UpdateMeetingExplain() { string explain = Request["explain"]; if (string.IsNullOrWhiteSpace(explain)) { return(JsonHelper.AnalysisJson <string>("请填写摘要", "ok", null)); } KfMeeting kfMeeting = _kfMeetingService.GetById(KfMeetingId); kfMeeting.Explain = explain; _kfMeetingService.Update(kfMeeting); return(JsonHelper.AnalysisJson <string>(kfMeeting.Explain, "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 string RejectKfMeeting() { KfMeeting kfMeeting = _kfMeetingService.GetById(KfMeetingId); if (!kfMeeting.IsEnd) { kfMeeting.IsEnd = true; _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(), "4", "0", kfMeeting.MpUserId.ToString() }, ref message); } //向用户发送已经拒绝的消息 string message2 = string.Empty; new CommandManager(null).TryHandleCommand("SendPrivateMessage", new string[] { KfNumberId.ToString(), kfMeeting.MpUserId.ToString(), "客服拒绝您的本次请求,请再次输入【客服】或【kf】转人工客服" }, ref message2); //把消息发送给微信端客户 MpUser mpUser = _mpUserService.GetById(kfMeeting.MpUserId); if (mpUser != null && !string.IsNullOrWhiteSpace(mpUser.OpenID)) { _mpUserService.SendMessage(mpUser.OpenID, "客服连接超时,您可以拨打我行客服热线40008-96336"); } } else { //向其他客服发送当前客户已经拒绝的通知 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(), "4", "0", kfMeeting.MpUserId.ToString() }, ref message); } } //更新用户状态 _mpUserService.ChangeMpUserState(kfMeeting.MpUserId, 0); return(JsonHelper.AnalysisJson <string>(string.Empty, "ok", null)); }
public KfMeetingDTO(KfMeeting kfMeeting) { this.Id = kfMeeting.Id; this.CreateDate = kfMeeting.CreateDate; this.KfNumberId = kfMeeting.KfNumberId; if (kfMeeting.KfNumber != null) { this.NickName = kfMeeting.KfNumber.NickName; } else { this.NickName = string.Empty; } this.MpUserId = kfMeeting.MpUserId; if (kfMeeting.MpUser != null) { this.MpUserName = kfMeeting.MpUser.NickName; } else { this.MpUserName = string.Empty; } this.RecordCount = kfMeeting.RecordCount; this.BeginDate = kfMeeting.BeginDate; this.EndDate = kfMeeting.EndDate; this.MeetingPage = kfMeeting.MeetingPage; this.Explain = kfMeeting.Explain; this.IsEnd = kfMeeting.IsEnd; if (EndDate.HasValue) { TimeSpan ts = EndDate.Value.Subtract(BeginDate); this.Duration = ts.Hours + "小时" + ts.Minutes + "分钟" + ts.Seconds + "秒"; } else { this.Duration = string.Empty; } }
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)); }
public string GetMeetingExplain() { KfMeeting kfMeeting = _kfMeetingService.GetById(KfMeetingId); return(JsonHelper.AnalysisJson <string>(kfMeeting.Explain, "ok", null)); }