public IMessageHandler MessageRole(MiddleMessage message) { var request = message.RequestMessage as RequestVoiceMessage; if (request != null) { //sMyLog.Log("语音识别:" + request.Recognition); if (!String.IsNullOrEmpty(request.Recognition)) { if (request.Recognition.IndexOf("博客园文章") > -1) { return new CnblogsArticleNewsMessageHandler(); } if (request.Recognition.IndexOf("博客园") > -1) { return new CnblogsTextMessageHandler(); } return new DefaultMessageHandler(); } else { return new VoiceMessageHandler(); } } else { return new DefaultMessageHandler(); } }
public ResponseMessage HandlerRequestMessage(MiddleMessage message) { return new ResponseTextMessage(message.RequestMessage) { Content = "您声音真好听" }; }
public ResponseMessage HandlerRequestMessage(MiddleMessage msg) { return new ResponseTextMessage(msg.RequestMessage) { CreateTime = DateTime.Now.Ticks, Content = s_cnblogsMsg }; }
public IMessageHandler MessageRole(MiddleMessage msg) { try { return new MsgTypeMessageRole().MessageRole(msg); } catch { return new DefaultMessageHandler(); } }
public ResponseMessage HandlerRequestMessage(MiddleMessage msg) { //var request = new RequestTextMessage(xml); var response = new ResponseNewsMessage(msg.RequestMessage); var cnblogsFeed = new CnBlogsFeed(5); var articles = cnblogsFeed.GetTopCnblogsFeed(); response.ArticleCount = articles.Count; response.CreateTime = DateTime.Now.Ticks; response.Articles = articles; return response; }
public IMessageHandler MessageRole(MiddleMessage msg) { switch (msg.RequestMessage.MsgType) { case MsgType.Text: return new TextMessageRole().MessageRole(msg); case MsgType.Event: return new EventMessageRole().MessageRole(msg); default: return new DefaultMessageHandler(); } }
public IMessageHandler MessageRole(MiddleMessage msg) { var eventType = (Event)Enum.Parse(typeof(Event), msg.Element.Element("Event").Value, true); switch (eventType) { case Event.Subscribe: return new SubScribeEventMessageHandler(); case Event.Unsubscribe: return new UnSubScribeEventMessageHandler(); } return new DefaultMessageHandler(); }
public IMessageHandler MessageRole(MiddleMessage msg) { var request = (RequestTextMessage)msg.RequestMessage; if (request.Content.IndexOf("博客园文章") > -1) { return new CnblogsArticleNewsMessageHandler(); } if (request.Content.IndexOf("博客园") > -1) { return new CnblogsTextMessageHandler(); } return new DefaultMessageHandler(); }
public void VoiceRequestMessageTest() { var xml = @"<xml> <ToUserName><![CDATA[gh_4efbac7d38cc]]></ToUserName> <FromUserName><![CDATA[oI1_vjirqEuoDttmL-eRcsO-G9to]]></FromUserName> <CreateTime>1400120855</CreateTime> <MsgType><![CDATA[voice]]></MsgType> <MediaId><![CDATA[RXS7f4w1cns6KTMEeVRa46i0q7f8TM57Gr_c2AnOSrKfzE1GqB7q1zYhpj_xVVKf]]></MediaId> <Format><![CDATA[amr]]></Format> <MsgId>6013473282672558080</MsgId> <Recognition><![CDATA[我可怜不可怜博客园]]></Recognition> </xml>"; var doc = XDocument.Parse(xml); var midder = new MiddleMessage(doc.Element("xml")); var request = midder.RequestMessage as RequestVoiceMessage; if (request != null) { Console.WriteLine(request.Recognition); } }
protected void Page_Load(object sender, EventArgs e) { try { //微信服务器一直把用户发过来的消息,post过来 if (Request.HttpMethod == "POST") { var reader = XmlReader.Create(Request.InputStream); var doc = XDocument.Load(reader); MyLog.Log(doc.ToString()); var xml = doc.Element("xml"); var msg = new MiddleMessage(xml); //把inputstream转换成xelement后,直接交给WebMessageRole来处理吧 var responseMessage = new WebMessageRole() .MessageRole(msg) .HandlerRequestMessage(msg); if (responseMessage != null) { Response.Write(responseMessage.Serializable()); #if DEBUG MyLog.Log(responseMessage.Serializable()); #endif } } else if (Request.HttpMethod == "GET") //微信服务器在首次验证时,需要进行一些验证,但。。。。 { //我仅需返回给他echostr中的值,就为验证成功,可能微信觉得这些安全策略是为了保障我的服务器,要不要随你吧 Response.Write(Request["echostr"].ToString()); } } catch (Exception ex) { MyLog.Log("error:" + ex.ToString()); } }
public ResponseMessage HandlerRequestMessage(MiddleMessage message) { return null; }