新建一个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. shakes hands

    Description On February, 30th n students came in the Center for Training Olympiad Programmers (CTOP) ...

  2. Hbase初体验

    搭建local模式搭建, 官网:http://hbase.apache.org API:http://hbase.apache.org/apidocs/index.html download:http ...

  3. 采用管道处理HTTP请求

    采用管道处理HTTP请求 之所以称ASP.NET Core是一个Web开发平台,源于它具有一个极具扩展性的请求处理管道,我们可以通过这个管道的定制来满足各种场景下的HTTP处理需求.ASP. NET ...

  4. 基于visual Studio2013解决面试题之0206hash表实现

     题目

  5. jni 入门 android的C编程之旅 --->环境搭建&&helloworld

    需要进行jni的开发有一下几个条件: 1:能初步使用C/C++如果不会,请参读 谭浩强的  C编程语言 2:android应用开发已经基本入门,如果没有,请先行学习 这两个条件基本满足后,我们开始了: ...

  6. 插件 - 提示窗体(ArtDialog)

    效果: 代码: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default. ...

  7. Android菜鸟的成长笔记(7)——什么是Activity

    原文:[置顶] Android菜鸟的成长笔记(7)——什么是Activity 前面我们做了一个小例子,在分析代码的时候我们提到了Activity,那么什么是Activity呢? Activity是An ...

  8. 10881 - Piotr's Ants

    Problem D Piotr's Ants Time Limit: 2 seconds "One thing is for certain: there is no stopping th ...

  9. “聊天剽窃手”--ptrace进程注入型病毒

    近日,百度安全实验室发现了一款"聊天剽窃手"病毒.该病毒可以通过ptrace方式注入恶意代码至QQ.微信程序进程.恶意代码可以实时监控手机QQ.微信的聊天内容及联系人信息. 该病毒 ...

  10. AIR

    There is a meaning for wings that cannot fly,it's a previous memory of when you once flew through th ...