public async Task <AcceptWecharState> CreateAcceptWecharState(AcceptWecharState AcceptWecharStateInfo) { //AcceptWecharStateInfo.Id= _repository.InsertAndGetId(AcceptWecharStateInfo); //return AcceptWecharStateInfo; // 不做数据返回操作 return(await _repository.InsertAsync(AcceptWecharStateInfo)); }
/// <summary> /// 接受消息 /// </summary> /// <param name="requestDoc"></param> /// <returns></returns> public async Task <ObjectResultModule> AcceptWechar(XDocument requestDoc) { using (var unitOfWork = _unitOfWorkManager.Begin()) { // 将接收到的消息存储 AcceptTencentWechar acceptTencentWechar = new AcceptTencentWechar(); acceptTencentWechar.ToUserName = JsonHelper.GetXmlValue(requestDoc, "ToUserName"); acceptTencentWechar.FromUserName = JsonHelper.GetXmlValue(requestDoc, "FromUserName"); acceptTencentWechar.CreateTime = JsonHelper.GetXmlValue(requestDoc, "CreateTime"); acceptTencentWechar.MsgType = JsonHelper.GetXmlValue(requestDoc, "MsgType"); acceptTencentWechar.Content = JsonHelper.GetXmlValue(requestDoc, "Content"); acceptTencentWechar.PicUrl = JsonHelper.GetXmlValue(requestDoc, "PicUrl"); acceptTencentWechar.MediaId = JsonHelper.GetXmlValue(requestDoc, "MediaId"); acceptTencentWechar.ThumbMediaId = JsonHelper.GetXmlValue(requestDoc, "ThumbMediaId"); acceptTencentWechar.Format = JsonHelper.GetXmlValue(requestDoc, "Format"); acceptTencentWechar.Recognition = JsonHelper.GetXmlValue(requestDoc, "Recognition"); acceptTencentWechar.Title = JsonHelper.GetXmlValue(requestDoc, "Title"); acceptTencentWechar.Description = JsonHelper.GetXmlValue(requestDoc, "Description"); acceptTencentWechar.Url = JsonHelper.GetXmlValue(requestDoc, "Url"); acceptTencentWechar.Location_X = JsonHelper.GetXmlValue(requestDoc, "Location_X"); acceptTencentWechar.Location_Y = JsonHelper.GetXmlValue(requestDoc, "Location_Y"); acceptTencentWechar.Scale = JsonHelper.GetXmlValue(requestDoc, "Scale"); acceptTencentWechar.Label = JsonHelper.GetXmlValue(requestDoc, "Label"); acceptTencentWechar.MsgId = JsonHelper.GetXmlValue(requestDoc, "MsgId"); acceptTencentWechar.MessageFrom = "Consultant"; if (acceptTencentWechar.FromUserName == null) { return(new ObjectResultModule("", 401, "")); } // SystemToken systemToken = new SystemToken(); // systemToken.TokenType = "Wechar"; var Tokens = _systemTokenService.SystemTokenList("Wechar").Result; string access_token = Tokens.access_token; // 检测用户信息 YaeherUser YaerherUser = new YaeherUser(); try { TencentUserManage usermanage = new TencentUserManage(); var usermsg = usermanage.WeiXinUserInfoUtils(acceptTencentWechar.FromUserName, Tokens.access_token).Result; if (usermsg.subscribe != 0) { string OperType = "用户咨询客服"; YaerherUser = await _yaeherUserService.YaeherUserInfo(usermsg, access_token, OperType); #region 检测发送消息状态 acceptTencentWechar.FullName = YaerherUser.FullName; // 用户全称 acceptTencentWechar.CreatedBy = YaerherUser.Id; // 用户ID acceptTencentWechar.UserImage = YaerherUser.UserImage; // 增加用户图像 acceptTencentWechar.NickName = YaerherUser.NickName; // 增加用户昵称 //检测是否客服跟进 AcceptWecharStateIn acceptWecharStateIn = new AcceptWecharStateIn(); acceptWecharStateIn.AndAlso(a => a.ConsultantOpenID == acceptTencentWechar.FromUserName); var StateList = await _acceptWecharStateService.WecharStateList(acceptWecharStateIn); AcceptWecharState acceptWecharState = StateList.FirstOrDefault(); bool OverTime = false; string AcceptState = string.Empty; if (acceptWecharState != null) { OverTime = acceptWecharState.AcceptTime.AddHours(2) < DateTime.Now; AcceptState = acceptWecharState.AcceptState; if (OverTime == true || acceptWecharState.AcceptState == "3") { // 需要根据当前客服排班记录查询 acceptWecharState.CustomerServiceID = 0; acceptWecharState.CustomerServiceName = "客服"; acceptWecharState.CustomerServiceJson = "客服"; } acceptWecharState.AcceptState = "2"; acceptWecharState.UserImage = YaerherUser.UserImage; // 增加用户图像 acceptWecharState.NickName = YaerherUser.NickName; // 增加用户昵称 acceptWecharState.ConsultantID = YaerherUser.Id; acceptWecharState.ConsultantName = YaerherUser.FullName; acceptWecharState.ConsultantJSON = JsonHelper.ToJson(YaerherUser); acceptWecharState.IsReady = false; acceptWecharState.AcceptTime = DateTime.Now; var UpdateState = await _acceptWecharStateService.UpdateAcceptWecharState(acceptWecharState); } else { AcceptWecharState WecharState = new AcceptWecharState(); // 需要根据当前客服排班记录查询 WecharState.CustomerServiceID = 0; WecharState.CustomerServiceName = "客服"; WecharState.CustomerServiceJson = "客服"; WecharState.UserImage = YaerherUser.UserImage; // 增加用户图像 WecharState.NickName = YaerherUser.NickName; // 增加用户昵称 WecharState.ConsultantID = YaerherUser.Id; WecharState.ConsultantName = YaerherUser.FullName; WecharState.ConsultantJSON = JsonHelper.ToJson(YaerherUser); WecharState.ConsultantOpenID = acceptTencentWechar.FromUserName; WecharState.AcceptState = "2"; WecharState.IsReady = false; WecharState.AcceptTime = DateTime.Now; //插入回复状态 var CreateState = await _acceptWecharStateService.CreateAcceptWecharState(WecharState); } #endregion // 插入接受消息 var Result = await _acceptTencentWecharService.CreateAcceptTencent(acceptTencentWechar); #region 关键字检索 string Content = string.Empty; // 将特殊符过滤掉 string KeyWord = new StringHepler().FilterString(acceptTencentWechar.Content).Trim(); if (string.IsNullOrEmpty(KeyWord)) { Content = null; } else { Content = _acceptTencentWecharService.SendWecharMesaage(KeyWord).Result; } if (string.IsNullOrEmpty(Content)) { Content = null; } #endregion // 当没客服跟进时先发送一条短信 if (acceptWecharState == null || AcceptState == "3" || OverTime || Content != null) { StringBuilder Contentsb = new StringBuilder(); Contentsb.Append("<a href=\"https://mp.weixin.qq.com/s/20iAOwP8Gzrq3zCdwMASng\">客服常见问题</a>\n"); Contentsb.Append("\n"); Contentsb.Append("客服工作时间: \n"); Contentsb.Append("周一到周五 9:00-17:30 \n"); Contentsb.Append("收到消息后我们会尽快反馈。\n"); Contentsb.Append("非工作时间请留言。\n"); // 增加问医生 Contentsb.Append("\n"); Contentsb.Append("<a href=\"" + Commons.WecharWeb + "?link=index-patient\">查看所有医生</a> "); if (Content != null) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(Content); // 增加问医生 stringBuilder.Append("\n"); stringBuilder.Append("<a href=\"" + Commons.WecharWeb + "?link=index-patient\">查看所有医生</a> "); Content = stringBuilder.ToString(); } // 回复消息 var textSingleMessage = new TextSingleMessage() { ToUser = acceptTencentWechar.FromUserName, TextContent = Content == null?Contentsb.ToString() : Content }; textSingleMessage.Send(Tokens.access_token).ToString(); } } } catch (Exception ex) { Logger.Info("我是一个发送消息的错误:" + ex.ToString() + "DateTime:" + DateTime.Now); } unitOfWork.Complete(); } return(new ObjectResultModule("", 200, "")); }
public async Task <AcceptWecharState> UpdateAcceptWecharState(AcceptWecharState AcceptWecharStateInfo) { return(await _repository.UpdateAsync(AcceptWecharStateInfo)); }