微信公众账号开发者接入验证
设置服务器配置的Url和Token
服务器方面站点验证代码
public void Valid() { if (Context.Request.RequestType == "GET") { string token = System.Configuration.ConfigurationManager.AppSettings["gaojuan_Token"].ToString(); string signature = Request.QueryString["signature"].ToString(); string timestamp = Request.QueryString["timestamp"].ToString(); string nonce = Request.QueryString["nonce"].ToString(); string echostr = Request.QueryString["echostr"].ToString();//随机字符串 bool isAccess = CheckSign(token, signature, timestamp, nonce); if (isAccess == true) Response.Write(echostr);//返回随机字符串 else Response.Write(echostr); Response.End(); } } /// <summary> /// 加密/校验流程如下: ///1. 将token、timestamp、nonce三个参数进行字典序排序 ///2. 将三个参数字符串拼接成一个字符串进行sha1加密 ///3. 开发者获得加密后的字符串可与signature对比,标识该请求来源于微信 /// </summary> /// <param name="token">token</param> /// <param name="signature">微信加密签名,signature结合了开发者填写的token参数和请求中的timestamp参数、nonce参数。</param> /// <param name="timestamp">时间戳 </param> /// <returns></returns> public bool CheckSign(string token, string signature, string timestamp, string nonce) { string[] strs = new string[] { token, timestamp, nonce }; Array.Sort(strs); string strNew = string.Join("", strs); strNew = FormsAuthentication.HashPasswordForStoringInConfigFile(strNew, "SHA1"); if (signature == strNew.ToLower()) return true; else return false; }