public ActionResult MiniPost(string signature, string timestamp, string nonce, string echostr) { if (!CheckSignature.Check(signature, timestamp, nonce, Token)) { return Content("参数错误!"); } var messageHandler = new CustomMessageHandler(Request.InputStream); messageHandler.Execute();//执行微信处理过程 return Content(messageHandler.ResponseDocument.ToString()); }
public ActionResult Post(string signature, string timestamp, string nonce, string echostr) { if (!CheckSignature.Check(signature, timestamp, nonce, Token)) { return Content("参数错误!"); } //自定义MessageHandler,对微信请求的详细判断操作都在这里面。 var messageHandler = new CustomMessageHandler(Request.InputStream); try { //测试时可开启此记录,帮助跟踪数据 messageHandler.RequestDocument.Save(Server.MapPath("~/App_Data/" + DateTime.Now.Ticks + "_Request_" + messageHandler.RequestMessage.FromUserName + ".txt")); //执行微信处理过程 messageHandler.Execute(); //测试时可开启,帮助跟踪数据 messageHandler.ResponseDocument.Save(Server.MapPath("~/App_Data/" + DateTime.Now.Ticks + "_Response_" + messageHandler.ResponseMessage.ToUserName + ".txt")); return Content(messageHandler.ResponseDocument.ToString()); } catch (Exception ex) { using (TextWriter tw = new StreamWriter(Server.MapPath("~/App_Data/Error_" + DateTime.Now.Ticks + ".txt"))) { tw.WriteLine(ex.Message); tw.WriteLine(ex.InnerException.Message); if (messageHandler.ResponseDocument != null) { tw.WriteLine(messageHandler.ResponseDocument.ToString()); } tw.Flush(); tw.Close(); } return Content(""); } }