public ActionResult KfNumberEdit() { string id = RQuery["Id"]; KfNumber kfNumber = string.IsNullOrWhiteSpace(id) ? null : _kfNumberService.GetById(new Guid(id)); return(AdminView(kfNumber)); }
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 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()); } } }