public ActionResult Post(PostModel postModel) { if (!CheckSignature.Check(postModel.Signature, postModel.Timestamp, postModel.Nonce, Config.WX_Token)) { return(Content("参数错误!")); } postModel.Token = Config.WX_Token; postModel.EncodingAESKey = Config.WX_EncodingAESKey; postModel.AppId = Config.WX_AppId; //v4.2.2之后的版本,可以设置每个人上下文消息储存的最大数量,防止内存占用过多,如果该参数小于等于0,则不限制 var maxRecordCount = 10; //自定义MessageHandler,对微信请求的详细判断操作都在这里面。 var messageHandler = new WxHandler(Request.InputStream, postModel, maxRecordCount); //debug.log("事件_" + (messageHandler.RequestMessage as IRequestMessageEventBase).Event.ToString(), ""); try { messageHandler.OmitRepeatedMessage = true; //执行微信处理过程 messageHandler.Execute(); return(new FixWeixinBugWeixinResult(messageHandler));//为了解决官方微信5.0软件换行bug暂时添加的方法,平时用下面一个方法即可 //return new WeixinResult(messageHandler);//v0.8+ } catch (Exception ex) { using (TextWriter tw = new StreamWriter(Server.MapPath("~/App_Data/Error_" + DateTime.Now.Ticks + ".txt"))) { tw.WriteLine("ExecptionMessage:" + ex.Message); tw.WriteLine(ex.Source); tw.WriteLine(ex.StackTrace); //tw.WriteLine("InnerExecptionMessage:" + ex.InnerException.Message); if (messageHandler.ResponseDocument != null) { tw.WriteLine(messageHandler.ResponseDocument.ToString()); } if (ex.InnerException != null) { tw.WriteLine("========= InnerException ========="); tw.WriteLine(ex.InnerException.Message); tw.WriteLine(ex.InnerException.Source); tw.WriteLine(ex.InnerException.StackTrace); } tw.Flush(); tw.Close(); } return(Content("")); } }
public ActionResult MiniPost(PostModel postModel) { if (!CheckSignature.Check(postModel.Signature, postModel.Timestamp, postModel.Nonce, Config.WX_Token)) { //return Content("参数错误!");//v0.7- return(new WeixinResult("参数错误!"));//v0.8+ } postModel.Token = Config.WX_Token; postModel.EncodingAESKey = Config.WX_EncodingAESKey; //根据自己后台的设置保持一致 postModel.AppId = Config.WX_AppId; //根据自己后台的设置保持一致 var messageHandler = new WxHandler(Request.InputStream, postModel, 10); messageHandler.Execute();//执行微信处理过程 //return Content(messageHandler.ResponseDocument.ToString());//v0.7- return(new FixWeixinBugWeixinResult(messageHandler)); //v0.8+ return(new WeixinResult(messageHandler)); //v0.8+ }