Asp.net Core 微信公眾號開發系列
阿新 • • 發佈:2017-12-11
net 配置 splay targe www -- c-s mage cnblogs
參考:http://www.cnblogs.com/zskbll/p/4074855.html
一、微信公眾平臺操作流程
1、先到微信公眾平臺註冊賬號
2、登錄成功後找到開發-->開發者工具-->公眾平臺測試帳號,點擊進入
3、到測試賬號管理配置你的服務器地址、跟Token。附測試接口源碼。
源碼信息如下
/// <summary> /// 驗證微信簽名 /// </summary> /// * 將token、timestamp、nonce三個參數進行字典序排序 /// * 將三個參數字符串拼接成一個字符串進行sha1加密 /// * 開發者獲得加密後的字符串可與signature對比,標識該請求來源於微信。微信測試接口/// <returns></returns> [HttpGet] public ActionResult WeChatCheck(string signature, string timestamp, string nonce, string echostr, string token) { string[] ArrTmp = { "wechat", timestamp, nonce }; //字典排序 Array.Sort(ArrTmp); string tmpStr = string.Join("", ArrTmp); //字符加密var sha1 = HmacSha1Sign(tmpStr); if (sha1.Equals(signature)) { return Content(echostr); } else { return null; } } /// <summary> /// HMAC-SHA1加密算法 /// </summary> /// <param name="str">加密字符串</param> /// <returns></returns> public stringHmacSha1Sign(string str) { var sha1 = System.Security.Cryptography.SHA1.Create(); var hash = sha1.ComputeHash(Encoding.Default.GetBytes(str)); string byte2String = null; for (int i = 0; i < hash.Length; i++) { byte2String += hash[i].ToString("x2"); } return byte2String; }
Asp.net Core 微信公眾號開發系列