微信公众账号开发者接入验证

设置服务器配置的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;
        }
 
  

 

 
 

转载于:https://www.cnblogs.com/jesn/articles/3552739.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值