using System; using System.Data; using System.Configuration; using System.Web; using System.Net; using System.IO; using System.Security.Cryptography; using System.Xml; using System.Collections.Specialized; using System.Text.RegularExpressions; using System.Collections.Generic; using System.Text; using System.Globalization; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data; using System.Data.SqlClient; using System.Web.Script.Serialization; namespace Mtxfw.shop { public partial class weixintoken0 : System.Web.UI.Page { /// /// 填写你申请的登录资料 /// public Mtxfw.Utility.Config config = new Mtxfw.Utility.Config(""); public Mtxfw.DAL.Article daoArt = new Mtxfw.DAL.Article(); public Mtxfw.DAL.user_info daoUser = new Mtxfw.DAL.user_info(); public int gtype = 0; protected void Page_Load(object sender, EventArgs e) { string hostname = Request.Url.Host; gtype = new DAL.host().GetId(hostname); if (!IsPostBack) { if (Request.QueryString["echoStr"] != null) { string echoStr = Request.QueryString["echoStr"]; if (CheckSignature()) { if (!string.IsNullOrEmpty(echoStr)) { Response.Write(echoStr); Response.End(); } } } } } /// /// 验证微信签名 /// /// * 将token、timestamp、nonce三个参数进行字典序排序 /// * 将三个参数字符串拼接成一个字符串进行sha1加密 /// * 开发者获得加密后的字符串可与signature对比,标识该请求来源于微信。 /// private bool CheckSignature() { string signature = Request.QueryString["signature"]; string timestamp = Request.QueryString["timestamp"]; string nonce = Request.QueryString["nonce"]; Mtxfw.Utility.Common.WriteHtml("/weixin/weixin0.txt", timestamp + "|" + nonce); string[] ArrTmp = { config.webToken, timestamp, nonce }; Array.Sort(ArrTmp); //字典排序 string tmpStr = string.Join("", ArrTmp); tmpStr = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(tmpStr, "SHA1"); tmpStr = tmpStr.ToLower(); if (tmpStr == signature) { return true; } else { return false; } } } }