亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

微信開發(fā)(一) asp.net接入

 更新時間:2016年05月09日 09:17:56   作者:lvzhongjian  
我們要進行微信公眾平臺的開發(fā),第一步當然是要有公眾號了。什么?不知道什么是微信公眾號,看來你還要先回爐煉煉了,呵呵。通俗的說,我們微信平臺就好像是一個大社會,里面有個體人,也有各種組織機構(gòu)。

 

        想要微信開發(fā),首先要有個服務器,但是自己沒有。這時候可以用花生殼,將內(nèi)網(wǎng)映射到公網(wǎng)上,這樣就可以在公網(wǎng)訪問自己的網(wǎng)站了。具體見:http://chabaoo.cn/article/83783.htm

        然后要寫一個接入代碼,而微信上只有php是示例。這里附上asp.net的示例。

        首先創(chuàng)建一個Default.aspx。在Page_Load里進行檢驗:(MyLog是日志類,可以忽略)   關(guān)于checkSignature()就和所查到的差不多了。這里貼一下
     

 MyLog.DebugInfo("request default.aspx");
 String echoStr = Request.QueryString["echostr"];
 MyLog.DebugInfo("echoStr:"+echoStr);
 if (this.checkSignature())
 {
 if(!string.IsNullOrEmpty(echoStr)){
 MyLog.DebugInfo("echostr:" + echoStr);
 Response.Write(echoStr);
 Response.End();
 }
 
 }

最最主要的是那句Response.End(),不加這一句怎么樣都接不進去(希望有大神告知)。 關(guān)于checkSignature()就和所查到的差不多了。這里貼一下

private bool checkSignature()
{
 
 string signature = Request["signature"];
 string timestamp = Request["timestamp"];
 string nonce = Request["nonce"];
 MyLog.DebugInfo(String.Format("signature:{0},timestamp:{1},nonce:{2}", signature, timestamp, nonce));
 string token = TOKEN;
 string[] tmpArr = new string[] { token, timestamp, nonce };
 Array.Sort(tmpArr);
 string tmpStr = string.Join("", tmpArr);
 //sha1加密
 System.Security.Cryptography.SHA1 sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider();
 byte[] secArr = sha1.ComputeHash(System.Text.Encoding.Default.GetBytes(tmpStr));
 tmpStr = BitConverter.ToString(secArr).Replace("-", "").ToLower();
 MyLog.DebugInfo(String.Format("after parse:{0}", tmpStr));
 if (tmpStr == signature)
 {
 MyLog.DebugInfo("true");
 return true;
 }
 else
 {
 return false;
 }
}

        這里主要是因為那個Response.End()的問題,導致我搞了許久,特此記錄一下,希望幫助能幫助到的人。

        還有一點可能是因為微信服務器的原因Token驗證失敗,多點2次即可,別像我這樣只點一次?。。?!

相關(guān)文章

最新評論