1. 程式人生 > >C# 之小程序 webapi 認證 微信小程序CheckSignature 消息推送

C# 之小程序 webapi 認證 微信小程序CheckSignature 消息推送

return 程序 登錄 apps 平臺 ger file app bubuko

微信小程序想實現 模板消息推送的話

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.填寫服務器配置

然後就可以填寫服務器配置,提交驗證簽名了!

技術分享圖片

C# 之小程序 webapi 認證 微信小程序CheckSignature 消息推送