新建一个WxHandler.ashx

   public class WxHandler : IHttpHandler
{
public static string Msg;
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
if (context.Request.HttpMethod.ToLower().Equals("get"))
{
context.Response.Write(Msg);
//校验
VaildateUrl();
}
else
{
//接受并相应
HandleMsg();
}
} private void HandleMsg()
{
HttpContext context = HttpContext.Current;
Stream xmlStream = context.Request.InputStream;
XmlDocument doc = new XmlDocument();
doc.Load(xmlStream);
XmlElement rootElement = doc.DocumentElement;
string toUserName = rootElement.SelectSingleNode("ToUserName").InnerText;
string fromUserName = rootElement.SelectSingleNode("FromUserName").InnerText;
string msgType = rootElement.SelectSingleNode("MsgType").InnerText;
string content = rootElement.SelectSingleNode("Content").InnerText;
//Msg = string.Format("{0}--{1}--{2}---{3}",toUserName,fromUserName,msgType,content);
string xmlMsg = "<xml>" +
"<ToUserName><![CDATA[" + fromUserName + "]]></ToUserName>" +
"<FromUserName><![CDATA[" + toUserName + "]]></FromUserName>" +
"<CreateTime>" + GetCreateTime() + "</CreateTime>" +
"<MsgType><![CDATA[text]]></MsgType>" +
"<Content><![CDATA[亲爱的你给我说的是:" + content + ",你说这是什么意思呢?]]></Content></xml>";
Msg = xmlMsg;
context.Response.Write(xmlMsg);
}
private int GetCreateTime()
{
DateTime dateStart = new DateTime(, , , , , );
return (int)(DateTime.Now - dateStart).TotalSeconds;
}
private void VaildateUrl()
{
HttpContext context = HttpContext.Current;
string signature = context.Request["signature"];
string timestamp = context.Request["timestamp"];
string nonce = context.Request["nonce"];
string echostr = context.Request["echostr"];
string token = "huang";
string[] temp1 = { token, timestamp, nonce };
Array.Sort(temp1);
string temp2 = string.Join("", temp1);
string temp3 = FormsAuthentication.HashPasswordForStoringInConfigFile(temp2, "SHA1");
if (temp3.ToLower().Equals(signature))
{
context.Response.Write(echostr);
}
else
{
context.Response.Write("浏览器打开方式!!");
} } public bool IsReusable
{
get
{
return false;
}
}
}

微信简单Demo的更多相关文章

  1. 设计模式之单例模式的简单demo

    /* * 设计模式之单例模式的简单demo */ class Single { /* * 创建一个本类对象. * 和get/set方法思想一样,类不能直接调用对象 * 所以用private限制权限 * ...

  2. Spring的简单demo

    ---------------------------------------- 开发一个Spring的简单Demo,具体的步骤如下: 1.构造一个maven项目 2.在maven项目的pom.xml ...

  3. 使用Spring缓存的简单Demo

    使用Spring缓存的简单Demo 1. 首先创建Maven工程,在Pom中配置 <dependency> <groupId>org.springframework</g ...

  4. Managed DirectX中的DirectShow应用(简单Demo及源码)

    阅读目录 介绍 准备工作 环境搭建 简单Demo 显示效果 其他 Demo下载 介绍 DirectX是Microsoft开发的基于Windows平台的一组API,它是为高速的实时动画渲染.交互式音乐和 ...

  5. angular实现了一个简单demo,angular-weibo-favorites

    前面必须说一段 帮客户做了一个过渡期的项目,唯一的要求就是速度,我只是会点儿基础的php,于是就用tp帮客户做了这个项目.最近和客户架构沟通,后期想把项目重新做一下,就用现在最流行的技术,暂时想的使用 ...

  6. Solr配置与简单Demo[转]

    Solr配置与简单Demo 简介: solr是基于Lucene Java搜索库的企业级全文搜索引擎,目前是apache的一个项目.它的官方网址在http://lucene.apache.org/sol ...

  7. 二维码简单Demo

    二维码简单Demo 一.视图 @{ Layout = null; } <!DOCTYPE html> <html> <head> <meta name=&qu ...

  8. android JNI 简单demo(2)它JNI demo 写

    android JNI 简单demo(2)它JNI demo 写 一.搭建Cygwin 环境:http://blog.csdn.net/androidolblog/article/details/25 ...

  9. Ext简单demo示例

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...

随机推荐

  1. 486E - LIS of Sequence(LIS)

    题意:给一个长度为n的序列.问每一个数关于序列的LIS(longest increasing subsequence)是什么角色. 这里分了三种: 1.此数没有出如今随意一条LIS中 2.此数出如今至 ...

  2. delphi不同版本字符串类型的演化(要支持基于firemonkey的app调用,字符串最好使用olevariant类型)

    string,DELPHI2009以前的版本string=ansistring,一个字符占一个字节,DELPHI2009及以上版本string=unicodestring,一个字符占二个字节. cha ...

  3. Delphi中使用GDI+进行绘图(2)

    2)使用IGDIPlus接口 (1)下载安装所需软件 可以在以下地址下载IGDI+最新的安装程序. http://www.mitov.com/products/igdi+ www.igdiplus.o ...

  4. Jquery发送ajax请求以及datatype参数为text/JSON方式

    Jquery发送ajax请求以及datatype参数为text/JSON方式 1.方式一:datatype:'text' 2.方式二:datatype:'JSON' 3.使用gson-1.5.jar包 ...

  5. uva 10131 Is Bigger Smarter?(DAG最长路)

    题目连接:10131 - Is Bigger Smarter? 题目大意:给出n只大象的属性, 包括重量w, 智商s, 现在要求找到一个连续的序列, 要求每只大象的重量比前一只的大, 智商却要小, 输 ...

  6. Struts2 Action接收表单参数

    struts2 Action获取表单传值    1.通过属性驱动式    JSP:        <form action="sys/login.action" method ...

  7. 14.4.8 Configuring the InnoDB Master Thread IO Rate 配置InnoDB Master Thread I/O Rate

    14.4.8 Configuring the InnoDB Master Thread IO Rate 配置InnoDB Master Thread I/O Rate 主的master thread ...

  8. Java Web Services (1) - 第1章 Web服务快速入门

    SCRIPTS_DIR=/Users/liuzhaofu/opus-dev/product/tools/devPRODUCT_DIR=/Users/liuzhaofu/opus-dev/product ...

  9. C++ 11 右值引用以及std::move

    转载请注明出处:http://blog.csdn.net/luotuo44/article/details/46779063 新类型: int和int&是什么?都是类型.int是整数类型,in ...

  10. Python+Django+SAE系列教程14-----使表单更安全

    还记得我们上一章提到过的加入页面吗? watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaGVtZW5nMTk4MA==/font/5a6L5L2T/fonts ...