創建服務器與微信公衆平臺的連接,首先要有一個默認首頁提供程序的連接支持,該方法主要是獲取微信提供過來的4個參數,供比較是否可連接使用。服務器
其次,要有一個服務器地址與一個token(爲英文或數字,長度爲3-32位字符),將公衆平臺切換成開發模式已開啓的狀態。微信
而後即可以將服務器地址url和token粘貼到公衆平臺裏進行連接啦。微信公衆平臺
分享創建鏈接的代碼以下:url
string echoStr = Request.QueryString["echostr"]; string signature = Request.QueryString["signature"]; string timestamp = Request.QueryString["timestamp"]; string nonce = Request.QueryString["nonce"]; string tokenStr = "com001";//按本身需求定義或獲取一個token bool b = false; string[] arrTmp = new string[] { tokenStr, timestamp, nonce }; Array.Sort(arrTmp); string restr = arrTmp[0].ToString() + arrTmp[1].ToString() + arrTmp[2].ToString(); restr = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(restr, "SHA1").ToLower(); if (signature == restr) { b = true; } else { b = false; } if (b) { HttpContext.Current.Response.Write(echoStr); HttpContext.Current.Response.End(); } else { HttpContext.Current.Response.Write("驗證失敗"); HttpContext.Current.Response.End(); }