public void SendSingleMessage(string user, XmlNode TSubResultNode) { SendTextRequest str = new SendTextRequest(); str.agentid = Agentid; str.safe = "0"; str.touser = user; SendTextRequest.Text text = new SendTextRequest.Text(); str.msgtype = "text"; // TSubResultNode.SelectSingleNode("msgtype").InnerText; text.content = TSubResultNode.SelectSingleNode("content").InnerText; str.text = text; messageBiz.Send <SendTextRequest>(str); }
private void SendSingleMessage(string user, string message) { SendTextRequest str = new SendTextRequest(); str.agentid = Agentid; str.safe = "0"; str.touser = user; SendTextRequest.Text text = new SendTextRequest.Text(); str.msgtype = "text"; text.content = message; str.text = text; messageBiz.Send <SendTextRequest>(str); }
public string SendMessage(string inputMessage, string user) { string xmlFilePath = xmlPath; XmlDocument doc = new XmlDocument(); doc.Load(xmlFilePath); var rp = GetLusiResult(inputMessage); if (rp != null) { var res = rp.intents.OrderByDescending(x => x.score).First(); if (res.intent.ToLower() == "none" && rp.entities.Count == 0)//没有查到结果返回默认结果 { XmlNodeList NoResultNodeList = doc.SelectNodes("Results/NoResult"); if (NoResultNodeList != null) { foreach (XmlNode noResultNode in NoResultNodeList) { SendSingleMessage(user, noResultNode); } } } //else if (res.intent.ToLower() != "none" && rp.entities.Count == 0)//有搜到,但不能精确定位 //{ // SendTextRequest str = new SendTextRequest(); // str.agentid = Agentid; // str.safe = "0"; // str.touser = user; // SendTextRequest.Text text = new SendTextRequest.Text(); // str.msgtype = "text"; // text.content = "您是要搜索" + res.intent + "么?请再提供更多关键字来精确定位吧。"; // str.text = text; // messageBiz.Send<SendTextRequest>(str); //} else { bool HasFind = false; XmlNodeList ResultNodeList = doc.SelectNodes("Results/Result"); if (ResultNodeList != null) { foreach (XmlNode ResultNode in ResultNodeList) { if (rp.entities.Any() && ResultNode.Attributes["name"].Value != "" && res.intent.ToLower() == ResultNode.Attributes["name"].Value.ToLower())//查询贺卡/邀请卡 { foreach (XmlNode SubResultNode in ResultNode) { if (rp.entities.First().type == SubResultNode.Attributes["name"].Value)//贺卡/邀请卡::StarProducts" { foreach (XmlNode TSubResultNode in SubResultNode) { if (rp.entities.First().entity.ToLower() == TSubResultNode.Attributes["name"].Value) { if (TSubResultNode.SelectSingleNode("msgtype").InnerText == "text") { HasFind = true; SendSingleMessage(user, TSubResultNode); } else if (TSubResultNode.SelectSingleNode("msgtype").InnerText == "mpnews") { HasFind = true; SendMpMessage(user, TSubResultNode); } else if (TSubResultNode.SelectSingleNode("msgtype").InnerText == "image") { HasFind = true; SendImageMessage(user, TSubResultNode); } else if (TSubResultNode.SelectSingleNode("msgtype").InnerText == "news") { HasFind = true; SendNewsMessage(user, TSubResultNode); } } } } } } } if (!HasFind) { foreach (XmlNode ResultNode in ResultNodeList) { if (ResultNode.Attributes["name"].Value != "" && res.intent.ToLower() == ResultNode.Attributes["name"].Value.ToLower())//查询贺卡/邀请卡 { foreach (XmlNode SubResultNode in ResultNode) { if (SubResultNode.Attributes["name"].Value.ToLower() == "default")//查询贺卡/邀请卡 { if (SubResultNode.SelectSingleNode("msgtype").InnerText == "text") { HasFind = true; SendSingleMessage(user, SubResultNode); } else if (SubResultNode.SelectSingleNode("msgtype").InnerText == "mpnews") { HasFind = true; SendMpMessage(user, SubResultNode); } else if (SubResultNode.SelectSingleNode("msgtype").InnerText == "image") { HasFind = true; SendImageMessage(user, SubResultNode); } else if (SubResultNode.SelectSingleNode("msgtype").InnerText == "news") { HasFind = true; SendNewsMessage(user, SubResultNode); } } } } } } if (!HasFind) { SendTextRequest str = new SendTextRequest(); str.agentid = Agentid; str.safe = "0"; str.touser = user; SendTextRequest.Text text = new SendTextRequest.Text(); str.msgtype = "text"; text.content = "您是要搜索" + res.intent + "么?请再提供更多关键字来精确定位吧。"; str.text = text; messageBiz.Send <SendTextRequest>(str); } } } } return(""); }