微信開發(fā)(一) asp.net接入
想要微信開發(fā),首先要有個服務(wù)器,但是自己沒有。這時候可以用花生殼,將內(nèi)網(wǎng)映射到公網(wǎng)上,這樣就可以在公網(wǎng)訪問自己的網(wǎng)站了。具體見:http://www.dhdzp.com/article/83783.htm
然后要寫一個接入代碼,而微信上只有php是示例。這里附上asp.net的示例。
首先創(chuàng)建一個Default.aspx。在Page_Load里進(jìn)行檢驗(yàn):(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(),不加這一句怎么樣都接不進(jìn)去(希望有大神告知)。 關(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;
}
}
這里主要是因?yàn)槟莻€Response.End()的問題,導(dǎo)致我搞了許久,特此記錄一下,希望幫助能幫助到的人。
還有一點(diǎn)可能是因?yàn)槲⑿欧?wù)器的原因Token驗(yàn)證失敗,多點(diǎn)2次即可,別像我這樣只點(diǎn)一次啊?。?!
相關(guān)文章
Asp.net中的數(shù)據(jù)綁定Eval和Bind應(yīng)用示例
這篇文章主要介紹了Asp.net中的數(shù)據(jù)綁定Eval和Bind的應(yīng)用,需要的朋友可以參考下2014-05-05
運(yùn)行asp.net時出現(xiàn) http錯誤404-文件或目錄未找到
問題描述: http錯誤404-文件或目錄未找到的解決方法2009-03-03
ASP.NET服務(wù)器控件開發(fā)(1)封裝html
在我們的項(xiàng)目開發(fā)中,由于ASP.NET的服務(wù)器控件功能有限,所以我們經(jīng)常會自己定義特定的服務(wù)器控件,來滿足開發(fā)中特定的業(yè)務(wù)要求??梢娭廊绾伍_發(fā)ASP.NET服務(wù)器控件是非常有必要的2015-12-12
ASP.NET中利用Segments取得URL的文件名的一種方法分享
在ASP.NET中,取得請求頁的URL地址有多種方式,其中有一種方式取得網(wǎng)頁文件名。2011-09-09

