public ActionResult Callback(Entities.Request.PostModel postModel) { //此处的URL格式类型为:http://weixin.senparc.com/Open/Callback/$APPID$, 在RouteConfig中进行了配置,你也可以用自己的格式,只要和开放平台设置的一致。 //处理微信普通消息,可以直接使用公众号的MessageHandler。此处的URL也可以直接填写公众号普通的URL,如本Demo中的/Weixin访问地址。 var logPath = Server.MapPath(string.Format("~/App_Data/Open/{0}/", DateTime.Now.ToString("yyyy-MM-dd"))); if (!Directory.Exists(logPath)) { Directory.CreateDirectory(logPath); } postModel.Token = component_Token; postModel.EncodingAESKey = component_EncodingAESKey;//根据自己后台的设置保持一致 postModel.AppId = component_AppId;//根据自己后台的设置保持一致 var messageHandler = new OpenCheckMessageHandler(Request.InputStream, postModel, 10); messageHandler.RequestDocument.Save(Path.Combine(logPath, string.Format("{0}_Request_{1}.txt", DateTime.Now.Ticks, messageHandler.RequestMessage.FromUserName))); messageHandler.Execute();//执行 if (messageHandler.ResponseDocument != null) { messageHandler.ResponseDocument.Save(Path.Combine(logPath, string.Format("{0}_Response_{1}.txt", DateTime.Now.Ticks, messageHandler.RequestMessage.FromUserName))); } return new FixWeixinBugWeixinResult(messageHandler); }
public ActionResult Callback(Entities.Request.PostModel postModel) { //此处的URL格式类型为:http://weixin.senparc.com/Open/Callback/$APPID$, 在RouteConfig中进行了配置,你也可以用自己的格式,只要和开放平台设置的一致。 //处理微信普通消息,可以直接使用公众号的MessageHandler。此处的URL也可以直接填写公众号普通的URL,如本Demo中的/Weixin访问地址。 var logPath = Server.MapPath(string.Format("~/App_Data/Open/{0}/", DateTime.Now.ToString("yyyy-MM-dd"))); if (!Directory.Exists(logPath)) { Directory.CreateDirectory(logPath); } postModel.Token = component_Token; postModel.EncodingAESKey = component_EncodingAESKey; //根据自己后台的设置保持一致 postModel.AppId = component_AppId; //根据自己后台的设置保持一致 var maxRecordCount = 10; MessageHandler<CustomMessageContext> messageHandler = null; try { var checkPublish = false; //是否在“全网发布”阶段 if (checkPublish) { messageHandler = new OpenCheckMessageHandler(Request.InputStream, postModel, 10); } else { messageHandler = new CustomMessageHandler(Request.InputStream, postModel, maxRecordCount); } messageHandler.RequestDocument.Save(Path.Combine(logPath, string.Format("{0}_Request_{1}.txt", DateTime.Now.Ticks, messageHandler.RequestMessage.FromUserName))); messageHandler.Execute(); //执行 if (messageHandler.ResponseDocument != null) { messageHandler.ResponseDocument.Save(Path.Combine(logPath, string.Format("{0}_Response_{1}.txt", DateTime.Now.Ticks, messageHandler.RequestMessage.FromUserName))); } return new FixWeixinBugWeixinResult(messageHandler); } catch (Exception ex) { using ( TextWriter tw = new StreamWriter(Server.MapPath("~/App_Data/Open/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 Callback(Senparc.Weixin.MP.Entities.Request.PostModel postModel) { //此处的URL格式类型为:http://sdk.weixin.senparc.com/Open/Callback/$APPID$, 在RouteConfig中进行了配置,你也可以用自己的格式,只要和开放平台设置的一致。 //处理微信普通消息,可以直接使用公众号的MessageHandler。此处的URL也可以直接填写公众号普通的URL,如本Demo中的/Weixin访问地址。 var logPath = ServerUtility.ContentRootMapPath(string.Format("~/App_Data/Open/{0}/", SystemTime.Now.ToString("yyyy-MM-dd"))); if (!Directory.Exists(logPath)) { Directory.CreateDirectory(logPath); } postModel.Token = component_Token; postModel.EncodingAESKey = component_EncodingAESKey; //根据自己后台的设置保持一致 postModel.AppId = component_AppId; //根据自己后台的设置保持一致 var maxRecordCount = 10; MessageHandler <CustomMessageContext> messageHandler = null; try { var checkPublish = false; //是否在“全网发布”阶段 if (checkPublish) { messageHandler = new OpenCheckMessageHandler(Request.GetRequestMemoryStream(), postModel, 10); } else { messageHandler = new CustomMessageHandler(Request.GetRequestMemoryStream(), postModel, maxRecordCount); } messageHandler.SaveRequestMessageLog(); //记录 Request 日志(可选) messageHandler.Execute(); //执行微信处理过程(关键) messageHandler.SaveResponseMessageLog(); //记录 Response 日志(可选) return(new FixWeixinBugWeixinResult(messageHandler)); } catch (Exception ex) { using ( TextWriter tw = new StreamWriter(ServerUtility.ContentRootMapPath("~/App_Data/Open/Error_" + SystemTime.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 Callback(Senparc.Weixin.MP.Entities.Request.PostModel postModel) { //此处的URL格式类型为:http://wx.wftx666.com/Open/Callback/$APPID$, 在RouteConfig中进行了配置,你也可以用自己的格式,只要和开放平台设置的一致。 //处理微信普通消息,可以直接使用公众号的MessageHandler。此处的URL也可以直接填写公众号普通的URL,如本Demo中的/Weixin访问地址。 var logPath = Server.MapPath(string.Format("~/App_Data/Open/{0}/", DateTime.Now.ToString("yyyy-MM-dd"))); if (!Directory.Exists(logPath)) { Directory.CreateDirectory(logPath); } WeixinTrace.SendCustomLog("记录APPID", "CallbackAppId:" + postModel.AppId); postModel.Token = component_Token; postModel.EncodingAESKey = component_EncodingAESKey; postModel.AppId = component_AppId; var maxRecordCount = 10; MessageHandler <CustomMessageContext> messageHandler = null; try { //是否在“全网发布”阶段 var checkPublish = false; if (checkPublish) { //全网发布测试处理 messageHandler = new OpenCheckMessageHandler(Request.InputStream, postModel, maxRecordCount); } else { //处理公众号消息 messageHandler = new CustomMessageHandler(Request.InputStream, postModel, maxRecordCount); } messageHandler.RequestDocument.Save(Path.Combine(logPath, string.Format("{0}_CallbackRequest_{1}.txt", DateTime.Now.Ticks, messageHandler.RequestMessage.FromUserName))); messageHandler.Execute(); //执行 if (messageHandler.ResponseDocument != null) { var ticks = DateTime.Now.Ticks; messageHandler.ResponseDocument.Save(Path.Combine(logPath, string.Format("{0}_CallbackResponse_{1}.txt", ticks, messageHandler.RequestMessage.FromUserName))); } return(new FixWeixinBugWeixinResult(messageHandler)); } catch (Exception ex) { using ( TextWriter tw = new StreamWriter(Server.MapPath("~/App_Data/Open/CallbackError_" + DateTime.Now.Ticks + ".txt"))) { tw.WriteLine("ExecptionMessage:" + ex.Message); tw.WriteLine(ex.Source); tw.WriteLine(ex.StackTrace); 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 Callback(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); } wx_openInfo wx_open = wx_openInfoService.instance().Single(new Guid(System.Configuration.ConfigurationManager.AppSettings["openID"])); postModel.EncodingAESKey = wx_open.open_sEncodingAESKey; //根据自己后台的设置保持一致 postModel.AppId = wx_open.open_sAppID; //根据自己后台的设置保持一致 postModel.Token = wx_open.open_sToken; var maxRecordCount = 10; MessageHandler<CustomMessageContext> messageHandler = null; try { var checkPublish = bool.Parse(System.Configuration.ConfigurationManager.AppSettings["checkPublish"]);// false; //是否在“全网发布”阶段 if (checkPublish) { messageHandler = new OpenCheckMessageHandler(Request.InputStream, postModel, 10); } else { messageHandler = new CustomMessageHandler(Request.InputStream, postModel, maxRecordCount); } messageHandler.RequestDocument.Save(Path.Combine(logPath, string.Format("{0}_Request_{1}.txt", DateTime.Now.Ticks, messageHandler.RequestMessage.FromUserName))); messageHandler.Execute(); //执行 return new FixWeixinBugWeixinResult(messageHandler); } catch (Exception ex) { using (TextWriter tw = new StreamWriter(Server.MapPath("~/App_Data/Open/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 Callback(Entities.Request.PostModel postModel, string clientId) { //此处的URL格式类型为:http://open.chainclouds.com/Open/Callback/$APPID$, 在RouteConfig中进行了配置,你也可以用自己的格式,只要和开放平台设置的一致。 //处理微信普通消息,可以直接使用公众号的MessageHandler。此处的URL也可以直接填写公众号普通的URL,如本Demo中的/Weixin访问地址。 //var logPath = Server.MapPath(string.Format("~/App_Data/Open/{0}/", DateTime.Now.ToString("yyyy-MM-dd"))); //if (!Directory.Exists(logPath)) //{ // Directory.CreateDirectory(logPath); //} postModel.Token = component_Token; postModel.EncodingAESKey = component_EncodingAESKey; //根据自己后台的设置保持一致 postModel.AppId = component_AppId; //根据自己后台的设置保持一致 var maxRecordCount = 10; MessageHandler <CustomMessageContext> messageHandler = null; try { var checkPublish = true; //是否在“全网发布”阶段 if (checkPublish) { messageHandler = new OpenCheckMessageHandler(Request.InputStream, postModel, 10); } else { messageHandler = new CustomMessageHandler(Request.InputStream, postModel, maxRecordCount); } //messageHandler.RequestDocument.Save(Path.Combine(logPath, // string.Format("{0}_Request_{1}.txt", DateTime.Now.Ticks, messageHandler.RequestMessage.FromUserName))); //调用老接口处理微信消息 var logsession = BaseService.GetWeixinLoggingSession(messageHandler.RequestMessage.ToUserName); messageHandler.CustomerId = logsession.ClientID; messageHandler.LoggingSession = logsession; var msgUrl = WebConfigurationManager.AppSettings["URL"] + "?" + this.Request.QueryString.ToString(); var msgResult = Utils.GetRemoteData(msgUrl, "POST", messageHandler.EcryptRequestDocument.ToString()); //var msgUrl = WebConfigurationManager.AppSettings["URL"]; //var msgResult = Utils.GetRemoteData(msgUrl, "POST", messageHandler.RequestDocument.ToString()); //if (msgResult.LastIndexOf("<xml>") > 0) //{ // msgResult = msgResult.Substring(0, msgResult.LastIndexOf("<xml>")); // //var tempMsg = msgResult.Substring(0, msgResult.LastIndexOf("<xml>")); //} Loggers.Debug(new DebugLogInfo() { Message = "msgResult 返回:" + msgResult }); //XmlDocument doc = new XmlDocument(); //doc.LoadXml(msgResult); //XDocument xdoc = XDocument.Parse(doc.ToString()); //ChainClouds.Weixin.MP.Entities.ResponseMessageBase.CreateResponseMessage(msgResult); //messageHandler.TextResponseMessage = msgResult; //if (!string.IsNullOrEmpty(msgResult)) return(Content(msgResult)); //else // messageHandler.Execute(); //执行 //if (messageHandler.ResponseDocument != null) //{ // messageHandler.ResponseDocument.Save(Path.Combine(logPath, // string.Format("{0}_Response_{1}.txt", DateTime.Now.Ticks, // messageHandler.RequestMessage.FromUserName))); //} //return new FixWeixinBugWeixinResult(messageHandler); } catch (Exception ex) { using ( TextWriter tw = new StreamWriter(Server.MapPath("~/App_Data/Open/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 Callback(Senparc.Weixin.MP.Entities.Request.PostModel postModel) { //此处的URL格式类型为:http://sdk.weixin.senparc.com/Open/Callback/$APPID$, 在RouteConfig中进行了配置,你也可以用自己的格式,只要和开放平台设置的一致。 //处理微信普通消息,可以直接使用公众号的MessageHandler。此处的URL也可以直接填写公众号普通的URL,如本Demo中的/Weixin访问地址。 var logPath = hostingEnvironment.MapPath(string.Format("~/App_Data/Open/{0}/", DateTime.Now.ToString("yyyy-MM-dd"))); if (!Directory.Exists(logPath)) { Directory.CreateDirectory(logPath); } postModel.Token = options.Token; postModel.EncodingAESKey = options.EncodingAESKey; //根据自己后台的设置保持一致 postModel.AppId = options.AppId; //根据自己后台的设置保持一致 var maxRecordCount = 10; MessageHandler <CustomMessageContext> messageHandler = null; try { string body = new StreamReader(Request.Body).ReadToEnd(); byte[] requestData = Encoding.UTF8.GetBytes(body); Stream inputStream = new MemoryStream(requestData); var checkPublish = false; //是否在“全网发布”阶段 if (checkPublish) { messageHandler = new OpenCheckMessageHandler(inputStream, postModel, options.AppId, options.AppSecret, hostingEnvironment, 10); } else { messageHandler = new CustomMessageHandler(inputStream, postModel, options.AppId, options.AppSecret, hostingEnvironment, maxRecordCount); } messageHandler.RequestDocument.Save(Path.Combine(logPath, string.Format("{0}_Request_{1}.txt", DateTime.Now.Ticks, messageHandler.RequestMessage.FromUserName))); messageHandler.Execute(); //执行 if (messageHandler.ResponseDocument != null) { var ticks = DateTime.Now.Ticks; messageHandler.ResponseDocument.Save(Path.Combine(logPath, string.Format("{0}_Response_{1}.txt", ticks, messageHandler.RequestMessage.FromUserName))); //记录加密后的日志 //if (messageHandler.UsingEcryptMessage) //{ // messageHandler.FinalResponseDocument.Save(Path.Combine(logPath, // string.Format("{0}_Response_Final_{1}.txt", ticks, // messageHandler.RequestMessage.FromUserName))); //} } return(new FixWeixinBugWeixinResult(messageHandler)); } catch (Exception ex) { using ( TextWriter tw = new StreamWriter(hostingEnvironment.MapPath("~/App_Data/Open/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("")); } } }