public ActionResult MiniPost(PostModel postModel) { if (!CheckSignature.Check(postModel.Signature, postModel.Timestamp, postModel.Nonce, Token)) { //return Content("参数错误!");//v0.7- return(new WeixinResult("参数错误!"));//v0.8+ } postModel.Token = Token; postModel.EncodingAESKey = EncodingAESKey; //根据自己后台的设置保持一致 postModel.AppId = AppId; //根据自己后台的设置保持一致 var messageHandler = new CustomMessageHandler(Request.InputStream, postModel, 10); messageHandler.Execute();//执行微信处理过程 //return Content(messageHandler.ResponseDocument.ToString());//v0.7- //return new WeixinResult(messageHandler);//v0.8+ var result = new FixWeixinBugWeixinResult(messageHandler);//v0.8+ LogHelper.WriteLog(LogEnum.Error, result.ToJson()); if (result.ToJson().Contains("success")) { return(Content("success")); } return(result); }
public ActionResult Post(PostModel postModel) { var maxRecordCount = 10; postModel.Token = Token; postModel.EncodingAESKey = EncodingAESKey; postModel.CorpId = CorpId; //自定义MessageHandler,对微信请求的详细判断操作都在这里面。 var messageHandler = new QyCustomMessageHandler(Request.InputStream, postModel, maxRecordCount); messageHandler.Execute(); var a = new FixWeixinBugWeixinResult(messageHandler); return(a);//为了解决官方微信5.0软件换行bug暂时添加的方法,平时用下面一个方法即可 }
public async Task <IActionResult> CommonMiniPost(PostModel postModel) { Logger.Info("接收事件处理=========================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================="); try { int mpId = Convert.ToInt32(Request.Query["MpID"]); var account = await _mpAccountAppService.GetCache(mpId); if (account == null) { Logger.Info(string.Format("微信回调错误:找不到MpID为{0}的公众号", mpId)); return(new WeixinResult("公众号或令牌不存在!")); //v0.8+ } postModel.Token = account.Token; postModel.EncodingAESKey = account.EncodingAESKey; //根据自己后台的设置保持一致 postModel.AppId = account.AppId; //根据自己后台的设置保持一致 if (!CheckSignature.Check(postModel.Signature, postModel.Timestamp, postModel.Nonce, postModel.Token)) { Logger.Info(string.Format("MpID为{0}的微信回调参数错误!", mpId)); return(new WeixinResult("参数错误!"));//v0.8+ } string body = new StreamReader(Request.Body).ReadToEnd(); byte[] requestData = Encoding.UTF8.GetBytes(body); Stream inputStream = new MemoryStream(requestData); var messageHandler = new CustomMessageHandler(inputStream, postModel, Logger, _cacheManager, _mpAccountAppService, mpId, _mpEventAppService, _mpMediaVideoAppService, _mpSelfArticleAppService, _mpSelfArticleGroupAppService, _mpSelfArticleGroupItemAppService, _mpEventRequestMsgLogAppService, _mpKeyWordReplyAppService, _mpEventClickViewLogAppService, _mpMenuAppService, _mpMessageAppService, _accessTokenContainer, _mpFanAppService, _mpEventScanLogAppService, _customerServiceResponseTextAppService, _mpUserMemberAppService, account, _mpChannelAppService, _iocResolver, _matialFileService, _webUrlService, _yiliBabyClubInterfaceService, 10); //messageHandler.UsingEcryptMessage = false; await messageHandler.ExecuteAsync(); //执行微信处理过程 var result = new FixWeixinBugWeixinResult(messageHandler); //v0.8+ Logger.Error("Content:" + result.Content); return(result); } catch (Exception e) { Logger.Error(e.Message); throw e; } }
public void MvcExtensionTest() { //同时测试TextResponseMessage是否生效 using (MemoryStream ms = new MemoryStream()) { using (StreamWriter sw = new StreamWriter(ms)) { string xml = InitXml(xmlTextFormat, "Hi, Senparc!"); sw.Write(xml); sw.Flush(); ms.Seek(0, SeekOrigin.Begin); var postModel = new PostModel(); var messageHandler = new TestMessageHandler(ms, postModel, 10); messageHandler.Execute(); var result = new FixWeixinBugWeixinResult(messageHandler); Assert.AreEqual("success", result.Content); } } }