C# 之小程序 webapi 认证 微信小程序CheckSignature 消息推送

微信小程序想实现 模板消息推送的话

1.登录到微信公众平台  - 小程序  - 开发 - 开发设置 。   找到消息推送

 2.验证消息的确来自微信服务器

    微信只提供了php检验的代码段,还缺少返回参数的方法

        // GET: Common
        /// <summary>
        ///  微信小程序模板校验签名
        /// </summary>
        /// <returns></returns>
        [System.Web.Http.HttpGet]
        public void  CheckSignature(string signature, string timestamp, string nonce, string echostr)
        {
            var token = ConfigurationManager.AppSettings["Token"];
            string[] ArrTmp = { token, timestamp, nonce };

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

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

            if (tmpStr == signature)
            {
                HttpContext.Current.Response.Write(echostr);
                HttpContext.Current.Response.End();
            }
            HttpContext.Current.Response.Write("校验失败");
            HttpContext.Current.Response.End();
        }

3.填写服务器配置

然后就可以填写服务器配置,提交验证签名了!

转载于:https://www.cnblogs.com/rock-dx/p/10560939.html

原文地址:https://www.cnblogs.com/vincentvoid/p/12058676.html