<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Collections.Generic;
using System.Web;
using System.IO;
using System.Text;
using System.Web.Security;
using System.Xml; public class Handler : IHttpHandler
{ public void ProcessRequest(HttpContext param_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, , (Int32)stream.Length);
postString = Encoding.Default.GetString(postBytes);
} if (!string.IsNullOrEmpty(postString))
{
Handle(postString);
}
}
else
{
InterfaceTest();
}
} public bool IsReusable
{
get
{
return false;
}
}
//写入日志
public void WriteLog(string text)
{
StreamWriter sw = new StreamWriter(HttpContext.Current.Server.MapPath(".") + "\\log.txt", true);
sw.WriteLine(text);
sw.Close();//写入
} /// <summary>
/// 处理信息并应答
/// </summary>
private void Handle(string postStr)
{
WriteLog(postStr); //记录微信服务器post字串
messageHelper help = new messageHelper();
string responseContent = help.ReturnMessage(postStr);
HttpContext.Current.Response.ContentEncoding = Encoding.UTF8;
HttpContext.Current.Response.Write(responseContent);
WriteLog(responseContent); //记录返回微信服务器字串 } //成为开发者url测试,返回echoStr
public void InterfaceTest()
{
string token = "填写的token";
if (string.IsNullOrEmpty(token))
{
return;
} string echoString = HttpContext.Current.Request.QueryString["echoStr"];
string signature = HttpContext.Current.Request.QueryString["signature"];
string timestamp = HttpContext.Current.Request.QueryString["timestamp"];
string nonce = HttpContext.Current.Request.QueryString["nonce"]; if (!string.IsNullOrEmpty(echoString))
{
HttpContext.Current.Response.Write(echoString);
HttpContext.Current.Response.End();
}
} }

最新文章

  1. EMF学习,为了实现可扩展可自定义的模型验证 - 各种实现方法学习
  2. 一道google面试题
  3. EF架构~在T4模版中为所有属性加默认值
  4. Android 的提权 (Root) 原理是什么?
  5. JAVA线程池的分析和使用
  6. 如何在linux环境下安装yaf
  7. POJ 3398 Perfect Service --最小支配集
  8. JAVA模块化
  9. SAP BW 重新初始化
  10. android中IdleHandler的使用
  11. 第48条:如果需要精确的答案,请避免使用float和double
  12. 淘淘商城_day05_课堂笔记
  13. 201521123050 《Java程序设计》第13周学习总结
  14. 系统启动时,dts怎么被加载的?
  15. Eclipse安装SVN插件(转载)
  16. JSX有感
  17. C语言面试笔记(8/26)
  18. springcloud流程图
  19. IOC容器特性注入第五篇:查找(Attribute)特性注入
  20. HTML5遇到的问题

热门文章

  1. attention发展历史及其相应论文
  2. caioj:1682: 【贪心】买一送一
  3. Android 渗透小知识点
  4. 3 web框架
  5. 关于IAR软件的Go to Definition of功能问题的解决方法
  6. (C)spring boot读取自定义配置文件时乱码解决办法
  7. 创建、导入、导出、复制以及粘贴 WMI 筛选器
  8. 后端接口迁移(从 webapi 到 openapi)前端经验总结
  9. Linux编译安装与配置-MySQL(5.5,5.6)版本系(笔记)
  10. Node应用进程管理器pm2的使用