public string OffLine() { string message = string.Empty; if (new CommandManager(null).TryHandleCommand("OffLine", new string[] { SendUserId.ToString(), "2" }, ref message)) { return(JsonHelper.AnalysisJson <string>(string.Empty, "ok", null)); } else { this.log.Error(message); return(JsonHelper.AnalysisJson <string>(message, "error", 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 SendPrivateMessage() { if (!string.IsNullOrWhiteSpace(Token)) { if (Token != "ocean") { return(JsonHelper.AnalysisJson <string>("凭证错误", "error", null)); } } try { string messageText = Request["messageText"]; if (string.IsNullOrWhiteSpace(messageText)) { return(JsonHelper.AnalysisJson <string>("消息不能为空", "error", null)); } messageText = messageText.Trim(); if (messageText == "接入") { return(StartKfMeeting()); } if (messageText == "断开") { return(EndKfMeeting()); } // 防止XSS攻击 //messageText = Sanitizer.GetSafeHtmlFragment(messageText); //messageText = HttpUtility.HtmlEncode(StringHelper.StripHtml(messageText)); messageText = HttpUtility.HtmlEncode(messageText); //把消息存入数据库 //ICommunicationRepository iCommunicationRepository = new PersistedRepository(); if (KfMeetingId == Guid.Empty) { return(JsonHelper.AnalysisJson <string>(string.Format("本条消息发送失败[{0}]", "您还没有建立会话"), "error", null)); } _kfMeetingMessageService.InsertKfMeetingMessage(KfMeetingId, 2, messageText); string message2 = string.Empty; if (new CommandManager(null).TryHandleCommand("SendPrivateMessage", new string[] { SendUserId.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)); } }