想要微信開發(fā),首先要有個(gè)服務(wù)器,但是自己沒有。這時(shí)候可以用花生殼,將內(nèi)網(wǎng)映射到公網(wǎng)上,這樣就可以在公網(wǎng)訪問自己的網(wǎng)站了。具體見:https://www.jb51.net/article/83783.htm
然后要寫一個(gè)接入代碼,而微信上只有php是示例。這里附上asp.net的示例。
首先創(chuàng)建一個(gè)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)槟莻€(gè)Response.End()的問題,導(dǎo)致我搞了許久,特此記錄一下,希望幫助能幫助到的人。
還有一點(diǎn)可能是因?yàn)槲⑿欧?wù)器的原因Token驗(yàn)證失敗,多點(diǎn)2次即可,別像我這樣只點(diǎn)一次?。。?!
您可能感興趣的文章:- .NET微信公眾號(hào) 用戶分組管理
- asp.net微信開發(fā)(用戶分組管理)
- asp.net微信開發(fā)(永久素材管理)
- asp.net微信開發(fā)(高級(jí)群發(fā)圖文)
- asp.net微信開發(fā)(高級(jí)群發(fā)文本)
- asp.net微信開發(fā)(已關(guān)注用戶管理)
- asp.net微信開發(fā)(消息應(yīng)答)
- asp.net微信開發(fā)(開發(fā)者接入)
- asp.net開發(fā)微信公眾平臺(tái)之獲取用戶消息并處理
- ASP.NET微信公眾號(hào)之用戶分組管理web頁面