/// <summary> /// 处理信息并应答 /// </summary> private void Handle(string postStr) { messageHelp help = new messageHelp(); string responseContent = help.ReturnMessage(postStr); HttpContext.Current.Response.ContentEncoding = Encoding.UTF8; HttpContext.Current.Response.Write(responseContent); }
/// <summary> /// 处理各种请求信息并应答(通过POST的请求) /// </summary> /// <param name="postStr">POST方式提交的数据</param> private void Execute(string postStr) { messageHelp mh = new messageHelp(); string responseContent = mh.ReturnMessage(postStr); HttpContext.Current.Response.ContentEncoding = Encoding.UTF8; HttpContext.Current.Response.Write(responseContent); }
/// <summary> /// 处理微信消息类型并应答 /// <param name="postStr">微信的XML字符串</param> /// </summary> public static void Handle(string postStr) { messageHelp help = new messageHelp(); string responseContent = help.ReturnMessage(postStr); HttpContext.Current.Response.ContentEncoding = Encoding.UTF8; //Common.LogManager.WriteLog("回复微信", responseContent); HttpContext.Current.Response.Write(responseContent); }
public string corpId = ConfigurationManager.AppSettings["CropID"]; //从配置文件获取corpId public void ProcessRequest(HttpContext context) { string postString = string.Empty; if (HttpContext.Current.Request.HttpMethod.ToUpper() == "POST") { using (Stream stream = HttpContext.Current.Request.InputStream) { Byte[] postBytes = new Byte[stream.Length]; stream.Read(postBytes, 0, (Int32)stream.Length); postString = Encoding.UTF8.GetString(postBytes); } if (!string.IsNullOrEmpty(postString)) { try { String sMsg = ""; WXBizMsgCrypt2 wxcpt = new WXBizMsgCrypt2(token, encodingAESKey, corpId); // WXBizMsgCrypt wxcpt = new WXBizMsgCrypt(token, encodingAESKey, corpId); String sVerifyMsgSig = context.Request.QueryString["msg_signature"]; String sVerifyTimeStamp = context.Request.QueryString["timestamp"]; String sVerifyNonce = context.Request.QueryString["nonce"]; int ret = wxcpt.DecryptMsg(sVerifyMsgSig, sVerifyTimeStamp, sVerifyNonce, postString, ref sMsg); LogTextHelper.Error("ret:" + ret + ",sMsg:" + sMsg); if (ret == 0) { messageHelp help = new messageHelp(); string responseContent = help.ReturnMessage(sMsg); int k = wxcpt.EncryptMsg(responseContent, sVerifyTimeStamp, sVerifyNonce, ref sMsg); LogTextHelper.Error("k:" + k); if (k == 0) { HttpContext.Current.Response.ContentEncoding = Encoding.UTF8; HttpContext.Current.Response.Write(sMsg); } } } catch (Exception ex) { LogTextHelper.Error(ex.ToString()); } } } else { Auth(); } }