微信公眾平台開發---建立服務器與微信公眾平台的鏈接


    建立服務器與微信公眾平台的鏈接,首先要有一個默認首頁提供程序的鏈接支持,該方法主要是獲取微信提供過來的4個參數,供比較是否可鏈接使用。

  其次,要有一個服務器地址與一個token(為英文或數字,長度為3-32位字符),將公眾平台切換成開發模式已開啟的狀態。

    然后便可以將服務器地址url和token粘貼到公眾平台里進行鏈接啦。

  分享建立連接的代碼如下:

            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();
                }

 


免責聲明!

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



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