public ActionResult Notice(PostModel postModel) { var logPath = hostingEnvironment.MapPath(string.Format("/App_Data/Open/{0}/", DateTime.Now.ToString("yyyy-MM-dd"))); if (!Directory.Exists(logPath)) { Directory.CreateDirectory(logPath); } //using (TextWriter tw = new StreamWriter(Path.Combine(logPath, string.Format("{0}_RequestStream.txt", DateTime.Now.Ticks)))) //{ // using (var sr = new StreamReader(Request.InputStream)) // { // tw.WriteLine(sr.ReadToEnd()); // tw.Flush(); // } //} //Request.InputStream.Seek(0, SeekOrigin.Begin); try { postModel.Token = options.Token; postModel.EncodingAESKey = options.EncodingAESKey; //根据自己后台的设置保持一致 postModel.AppId = options.AppId; //根据自己后台的设置保持一致 string body = new StreamReader(Request.Body).ReadToEnd(); byte[] requestData = Encoding.UTF8.GetBytes(body); Stream inputStream = new MemoryStream(requestData); var messageHandler = new CustomThirdPartyMessageHandler(inputStream, postModel, hostingEnvironment);//初始化 //注意:再进行“全网发布”时使用上面的CustomThirdPartyMessageHandler,发布完成之后使用正常的自定义的MessageHandler,例如下面一行。 //var messageHandler = new CommonService.CustomMessageHandler.CustomMessageHandler(Request.InputStream, // postModel, 10); //记录RequestMessage日志(可选) //messageHandler.EcryptRequestDocument.Save(Path.Combine(logPath, string.Format("{0}_Request.txt", DateTime.Now.Ticks))); messageHandler.RequestDocument.Save(Path.Combine(logPath, string.Format("{0}_Request_{1}.txt", DateTime.Now.Ticks, messageHandler.RequestMessage.AppId))); messageHandler.Execute();//执行 //记录ResponseMessage日志(可选) using (TextWriter tw = new StreamWriter(Path.Combine(logPath, string.Format("{0}_Response_{1}.txt", DateTime.Now.Ticks, messageHandler.RequestMessage.AppId)))) { tw.WriteLine(messageHandler.ResponseMessageText); tw.Flush(); tw.Close(); } return(Content(messageHandler.ResponseMessageText)); } catch (Exception ex) { throw; return(Content("error:" + ex.Message)); } }
public ActionResult Notice(PostModel postModel) { var logPath = ServerUtility.ContentRootMapPath(string.Format("~/App_Data/Open/{0}/", SystemTime.Now.ToString("yyyy-MM-dd"))); if (!Directory.Exists(logPath)) { Directory.CreateDirectory(logPath); } //using (TextWriter tw = new StreamWriter(Path.Combine(logPath, string.Format("{0}_RequestStream.txt", SystemTime.Now.Ticks)))) //{ // using (var sr = new StreamReader(Request.InputStream)) // { // tw.WriteLine(sr.ReadToEnd()); // tw.Flush(); // } //} //Request.InputStream.Seek(0, SeekOrigin.Begin); try { postModel.Token = component_Token; postModel.EncodingAESKey = component_EncodingAESKey; //根据自己后台的设置保持一致 postModel.AppId = component_AppId; //根据自己后台的设置保持一致 var messageHandler = new CustomThirdPartyMessageHandler(Request.GetRequestMemoryStream(), postModel);//初始化 //注意:在进行“全网发布”时使用上面的CustomThirdPartyMessageHandler,发布完成之后使用正常的自定义的MessageHandler,例如下面一行。 //var messageHandler = new CommonService.CustomMessageHandler.CustomMessageHandler(Request.GetRequestMemoryStream(), // postModel, 10); //记录RequestMessage日志(可选) //messageHandler.EcryptRequestDocument.Save(Path.Combine(logPath, string.Format("{0}_Request.txt", SystemTime.Now.Ticks))); messageHandler.RequestDocument.Save(Path.Combine(logPath, string.Format("{0}_Request_{1}.txt", SystemTime.Now.Ticks, messageHandler.RequestMessage.AppId))); messageHandler.Execute();//执行 //记录ResponseMessage日志(可选) using (TextWriter tw = new StreamWriter(Path.Combine(logPath, string.Format("{0}_Response_{1}.txt", SystemTime.Now.Ticks, messageHandler.RequestMessage.AppId)))) { tw.WriteLine(messageHandler.ResponseMessageText); tw.Flush(); tw.Close(); } return(Content(messageHandler.ResponseMessageText)); } catch //(Exception ex) { throw; //return Content("error:" + ex.Message); } }
public ActionResult Notice(PostModel postModel) { var logPath = Server.MapPath(string.Format("~/App_Data/Open/{0}/", DateTime.Now.ToString("yyyy-MM-dd"))); if (!Directory.Exists(logPath)) { Directory.CreateDirectory(logPath); } try { postModel.Token = component_Token; postModel.EncodingAESKey = component_EncodingAESKey; //根据自己后台的设置保持一致 postModel.AppId = component_AppId; //根据自己后台的设置保持一致 var messageHandler = new CustomThirdPartyMessageHandler(Request.InputStream, postModel); //初始化 //注意:再进行“全网发布”时使用上面的CustomThirdPartyMessageHandler,发布完成之后使用正常的自定义的MessageHandler,例如下面一行。 //var messageHandler = new CustomMessageHandler(Request.InputStream,postModel, 10); //记录RequestMessage日志(可选) messageHandler.RequestDocument.Save(Path.Combine(logPath, string.Format("{0}_NoticeRequest_{1}.txt", DateTime.Now.Ticks, messageHandler.RequestMessage.AppId) )); messageHandler.Execute();//执行 //记录ResponseMessage日志(可选) using (TextWriter tw = new StreamWriter(Path.Combine(logPath, string.Format("{0}_NoticeResponse_{1}.txt", DateTime.Now.Ticks, messageHandler.RequestMessage.AppId)))) { tw.WriteLine(messageHandler.ResponseMessageText); tw.Flush(); tw.Close(); } return(Content(messageHandler.ResponseMessageText)); } catch (Exception ex) { return(Content("error:" + ex.Message)); } }
/// <summary> /// 授权事件接收URL /// </summary> /// <returns></returns> public ActionResult Notice() { var messageHandler = new CustomThirdPartyMessageHandler(Request.InputStream); return(Content("success")); }