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 GetMpUserInfo() { MpUser mpUser = _mpUserService.GetById(ReceiveUserId); string isFnb = _funongbaoService.GetCount(" where MpUserId='" + ReceiveUserId + "'").ToString(); string extData = mpUser.CreateDate.ToString("yyyy-MM-dd") + "|" + mpUser.LastVisitDate.ToString("yyyy-MM-dd") + "|" + isFnb; return(JsonHelper.AnalysisJson <MpUser>(mpUser, "ok", extData)); }
/// <summary> /// 设置在线状态[0:正常,1:离开] /// </summary> /// <returns></returns> public string SetOnlineStatus() { int onlineStatus = int.Parse(Request["OnlineStatus"]); KfNumber kfNumber = _kfNumberService.GetById(KfNumberId); kfNumber.OnlineStatus = onlineStatus; _kfNumberService.Update(kfNumber); return(JsonHelper.AnalysisJson <string>(onlineStatus.ToString(), "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 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)); } }
/// <summary>根据Code获取用户的openid、access_token</summary> public static string GetOauthAccessOpenId(string code, string appid, string secret) { string Openid = ""; string url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + appid + "&secret=" + secret + "&code=" + code + "&grant_type=authorization_code"; string gethtml = MyHttpHelper.HttpGet(url); //ErrorLog.WriteErrorMessage("拿到的url是:" + url); //ErrorLog.WriteErrorMessage("获取到的gethtml是" + gethtml); OAuth_Token ac = new OAuth_Token(); ac = JsonHelper.AnalysisJson <OAuth_Token>(gethtml); //ErrorLog.WriteErrorMessage("能否从html里拿到openid=" + ac.openid); Openid = ac.openid; return(Openid); }
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 string OffLine() { string message = string.Empty; KfNumber kfNumber = _kfNumberService.GetById(KfNumberId); if (kfNumber == null) { return(JsonHelper.AnalysisJson <string>("KfNumber对象为null", "error", null)); } //发送客服离线通知 if (new CommandManager(null).TryHandleCommand("OffLine", new string[] { KfNumberId.ToString(), "1" }, ref message)) { return(JsonHelper.AnalysisJson <string>(string.Empty, "ok", null)); } else { this.log.Error(message); return(JsonHelper.AnalysisJson <string>(message, "error", null)); } }
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 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)); } }
public string GetMeetingExplain() { KfMeeting kfMeeting = _kfMeetingService.GetById(KfMeetingId); return(JsonHelper.AnalysisJson <string>(kfMeeting.Explain, "ok", null)); }