您的位置:首页 > 移动开发 > 微信开发

微信(服务器配置)

2016-03-05 16:36 507 查看
微信入门001(服务器配置)



通过url+token =è返回signature+timestamp+nonce+echostr

timestamp+nonce+ token 排序+sha1 加密=比较signature是否相等

注意:

url: 只能是备案的80 域名

token:32位随机数

timestamp:时间戳

nonce:随机数

echostr:随机字符串

代码如下:一般处理程序

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Web;
using System.Security.Authentication;
using System.Security.Cryptography;
using System.Web.Security;

namespace WebApplication1
{
/// <summary>
/// wx 的摘要说明
/// </summary>
public class wx : IHttpHandler
{
private string token = "hHneE6EtBEHxNamAkTsCvz5pA3mHWxT";
public void ProcessRequest(HttpContext context)
{
var url = context.Request.RawUrl;

//  /?signature=28b94e012e1d698990faf96460a904e334699c6b&echostr=3153896548757110783×tamp=1457086219&nonce=1453006066
//context.Response.ContentType = "text/plain";
//context.Response.Write("Hello World");

//三个参数排序 ==>放入数组中
var signature = context.Request.QueryString["signature"];
var timestamp = context.Request.QueryString["timestamp"];
var nonce = context.Request.QueryString["nonce"];
var echostr = context.Request.QueryString["echostr"];
var arr = new[] { token, timestamp, nonce };
Array.Sort(arr);
var tmepstr = string.Join("", arr);
var tempsignature=  FormsAuthentication.HashPasswordForStoringInConfigFile(tmepstr, "SHA1").ToLower();
if (signature == tempsignature)
{
context.Response.Write(echostr);
}

}

public bool IsReusable
{
get
{
return false;
}
}
}
}


结果 :



微信调试技巧:记得打开w3wp.exe 附件进程

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: