微信TOKEN验证源码

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.IO;
using System.Net;
using System.Text;
using System.Xml;
using System.Web.Security;

public partial class weixin : System.Web.UI.Page
{

const string Token = "token";//你的token

protected void Page_Load(object sender, EventArgs e)
{

string postStr = "";

if (Request.HttpMethod.ToLower() == "post")
{

System.IO.Stream s = System.Web.HttpContext.Current.Request.InputStream;

byte[] b = new byte[s.Length];

s.Read(b, 0, (int)s.Length);

postStr = System.Text.Encoding.UTF8.GetString(b);

if (!string.IsNullOrEmpty(postStr))
{

//ResponseMsg(postStr);

Response.Write(ResponseMsg(postStr));

Response.End();

}

//WriteLog("postStr:" + postStr);

}

else
{

Valid();

}

}

/// <summary>

/// 验证微信签名

/// </summary>

/// * 将token、timestamp、nonce三个参数进行字典序排序

/// * 将三个参数字符串拼接成一个字符串进行sha1加密

/// * 开发者获得加密后的字符串可与signature对比,标识该请求来源于微信。

/// <returns></returns>

private bool CheckSignature()
{

string signature = Request.QueryString["signature"].ToString();

string timestamp = Request.QueryString["timestamp"].ToString();

string nonce = Request.QueryString["nonce"].ToString();

string[] ArrTmp = { Token, timestamp, nonce };

Array.Sort(ArrTmp); //字典排序

string tmpStr = string.Join("", ArrTmp);

tmpStr = FormsAuthentication.HashPasswordForStoringInConfigFile(tmpStr, "SHA1");

tmpStr = tmpStr.ToLower();

if (tmpStr == signature)
{

return true;

}

else
{

return false;

}

}

private void Valid()
{

string echoStr = Request.QueryString["echoStr"].ToString();

if (CheckSignature())
{

if (!string.IsNullOrEmpty(echoStr))
{

Response.Write(echoStr);

Response.End();

}

}

}

/// <summary>

/// 返回信息结果(微信信息返回)

/// </summary>

/// <param name="weixinXML"></param>

private string ResponseMsg(string weixinXML)
{

///这里写你的返回信息代码
return "";

}

/// <summary>

/// unix时间转换为datetime

/// </summary>

/// <param name="timeStamp"></param>

/// <returns></returns>

private DateTime UnixTimeToTime(string timeStamp)
{

DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));

long lTime = long.Parse(timeStamp + "0000000");

TimeSpan toNow = new TimeSpan(lTime);

return dtStart.Add(toNow);

}

/// <summary>

/// datetime转换为unixtime

/// </summary>

/// <param name="time"></param>

/// <returns></returns>

private int ConvertDateTimeInt(System.DateTime time)
{

System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));

return (int)(time - startTime).TotalSeconds;

}

/// <summary>

/// 写日志(用于跟踪)

/// </summary>

private void WriteLog(string strMemo)
{

string filename = Server.MapPath("/logs/log.txt");

if (!Directory.Exists(Server.MapPath("//logs//")))

Directory.CreateDirectory("//logs//");

StreamWriter sr = null;

try
{

if (!File.Exists(filename))
{

sr = File.CreateText(filename);

}

else
{

sr = File.AppendText(filename);

}

sr.WriteLine(strMemo);

}

catch
{

}

finally
{

if (sr != null)

sr.Close();

}

}

}

微信TOKEN验证源码,布布扣,bubuko.com

时间: 2024-12-16 16:02:36

微信TOKEN验证源码的相关文章

微信token认证源码分享(c#版)

在开发时遇到一个问题: 上线后提交申请微信提示"您的服务器没有正确响应token验证...",我查看日志发现根本就没有接收到来自微信的参数. 后来我又记录了微信请求方式和请求的字符串,想看看微信服务器到底有没有给我的服务器响应请求.结果是有的.并且通过了. 代码就添加了Request.HttpMethod和Request.QueryString没变,但不晓得怎么回事. /// <summary> 按照api说明对signature进行校验,校验成功返回参数echostr &

微信熟人牛牛源码安装+人工智能+人机融合

1.群体智能https://h5.hxforum.com基于群体编辑的维基百科.微信熟人牛牛源码安装(h5.hxforum.com) 联系方式170618633533企鹅2952777280 源码出售 房卡出售 后台出租有意者私聊扣扣基于群体开发的开源软件.基于众问众答的知识共享.基于众筹众智的万众创新.基于众包众享的共享经济等等.<规划>提出的群体智能研究方向,实质上正是综合集成研讨厅在人工智能新时代的拓展和深化.它的研究内涵不单是关注精英专家团体,而是通过互联网组织结构和大数据驱动的人工智

微信北京赛车源码下载搭建

微信北京赛车源码下载搭建 http://hubawl.com 程序中可以定义为: @tf.custom_gradient def f3(x, n): v = tf.pow(x, n) def grad(dy): return (dy* (n*tf.pow(x, n-1)) ).numpy() return v.numpy(), grad def dp1_f1(x): return 64*x*(1-x)*f3(1-2*x,2)*f3(1-8*x+8*x*x, 2) 1 2 3 4 5 6 7 8

微信小程序源码下载(200多个)

微信小程序源码下载汇总,点击标题进入对应的微信小程序下载页面. 最新 demo源码(点击标题进入帖子下载) 描述 1 微信小程序 会议室预定小程序 微信小程序 会议室预定小程序**** 本内容被作者隐藏 **** 2 微信小程序-双人五子棋小游戏 微信小程序-双人五子棋小游戏**** 本内容被作者隐藏 **** 3 打卡签到小程序 用微信小程序实现的一个简单的打卡签到的小程序拒绝 4 微信小程序---左滑删除 微信小程序---左滑删除**** 本内容被作者隐藏 **** 5 一个借钱的记事本的微

11款手机微信小游戏源码特效

html5微信吃苹果游戏源码下载 html5手机淘宝万能时装屋小游戏源码下载 html5 3d拳王游戏制作3D拳击游戏源码下载 html5 3d拼图游戏制作3D魔方游戏源码下载 htm5 3d游戏制作3D熊出没游戏源码下载 html5微信小游戏超级染色游戏源码下载 html5读心术小游戏源码下载_读心术微信小游戏源码下载 找你歌微信html5游戏源码下载_找你歌微信游戏源码下载 方言等级考试游戏源码下载_方言等级测试微信游戏源码下载 中秋节吃月饼游戏html5微信游戏源码下载 9款html5微信

VS.NET2010 C#开发的微信公众平台源码

C#.NET微信公众平台源码,功能齐全 会员卡,微商城,微营销等等 源码已集成目前市场主流功能,并实时更新,应用商店更有大量贴心/实用/酷炫功能和模板可供自主添加 下载源码网站http://www.zhyin.com 演示地址http://cx010108.zhyin.com/admin/ 联系QQ:11851298

VS.NET NET4.0 C#.NET微信公众平台源码,功能齐全 微信源码

C#.NET微信公众平台源码,功能齐全 微信源码 会员卡,微商城,微营销等等 源码已集成目前市场主流功能,并实时更新,应用商店更有大量贴心/实用/酷炫功能和模板可供自主添加 演示地址http://cx010108.pssdss.com/admin/ 用户名 admin 密码 529 源码下载http://www.pssdss.com/d230.html 更多源码网站http://www.pssdss.com 联系QQ:11851298

.net 微信Token验证

首次接受这个项目,看了微信的API,云里雾里,经过几经测试,理清思路 开发者自个申请,微信API给出四个参数: 下面我解释下 signature 是微信加密签名 即:微信服务器将 timetamp nonce  token(你提交的)使用SHA1加密后 会使用GET方式发送给你. timestamp是腾讯服务器发送的一个时间戳 nonce是腾讯服务器发送的一个随机数 成功申请的关键是在下面,上面的几个参数只是 微信提供 用户请求--->你自己的网站 的一个验证方式. echostr就是 腾讯服务

IOS 即时通讯 + 微信聊天框架 + 源码

这些你造吗? 即时通讯(IM),在IOS这片江湖里面已经算是一个老者了,我这小旋风也是在很早以前巡山的时候,就知道有即时通讯这个妖怪,以前也多多少少接触过一些,在造APP的时候用过,哎呀,说着说着就感觉要跑题了,脑海中怎么波涛翻滚的样子.不好,才开头了两句,忍住!!说回正题,我知道的即时通讯有用 CocoaAsyncSocket 还有 XMPPFramework 实现的,当然也有现在也有大部分接入环信的.有些东西掩盖不住的,我是你知道的越多越会觉得自己是个文盲,会有很强烈的感觉,你不懂的真的好多