新建一个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. Eequal sum sets

    Let us consider sets of positive integers less than or equal to n. Note that all elements of a set a ...

  2. 14.1.1 InnoDB as the Default MySQL Storage Engine

    14.1 Introduction to InnoDB 14.1.1 InnoDB as the Default MySQL Storage Engine 14.1.2 Checking InnoDB ...

  3. 【Demo 0016】SQLite 数据库

    本章学习要点:       1.  熟悉SQL语句:       2.  掌握SQLit库的基本用法;        3.  掌握SQLite封装:

  4. Android - 隐藏最顶端的通知条(Top Notification Bar)

    隐藏最顶端的通知条(Top Notification Bar/ActionBar) 本文地址: http://blog.csdn.net/caroline_wendy Android中, 视频播放等功 ...

  5. HTML属性

  6. Indy的评价

    已经抛弃了indy,实在是不好,tcp在android下退出报错.我现在改用系统自带的httpclient.推荐RTC RTC带有一个tcp组件,不过处理方式跟indy不同,测试过,在android下 ...

  7. SilkTest Q&A 4

    Q31.如何在inc文件里面写函数? A31.在你在inc文件(例如demo.inc)里写好函数以后,你需要使用Use path/Use file来指定指定它们. 在SilkTest中->Opt ...

  8. UVA 10622 - Perfect P-th Powers(数论)

    UVA 10622 - Perfect P-th Powers 题目链接 题意:求n转化为b^p最大的p值 思路:对n分解质因子,然后取全部质因子个数的gcd就是答案,可是这题有个坑啊.就是输入的能够 ...

  9. Google 搜索的基本语法

    ★搜索引擎的选择 先简单说一下"搜索引擎的选择". 在咱们天朝,Google 屡屡被 GFW 骚扰,导致百度占了便宜,成为份额最高的搜索引擎.不过今天这篇教程,俺还是继续拿 Goo ...

  10. Android仿iOS7的UISegmentedControl 分段

    效果图: 这里仅仅简单做了两个button的. 首先是两个button的背景: res/drawable/seg_left.xml <?xml version="1.0" e ...