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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM