想要微信開發(fā),首先要有個服務器,但是自己沒有。這時候可以用花生殼,將內(nèi)網(wǎng)映射到公網(wǎng)上,這樣就可以在公網(wǎng)訪問自己的網(wǎng)站了。具體見:https://www.jb51.net/article/83783.htm
然后要寫一個接入代碼,而微信上只有php是示例。這里附上asp.net的示例。
首先創(chuàng)建一個Default.aspx。在Page_Load里進行檢驗:(MyLog是日志類,可以忽略) 關于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(),不加這一句怎么樣都接不進去(希望有大神告知)。 關于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次即可,別像我這樣只點一次?。。?!
您可能感興趣的文章:- .NET微信公眾號 用戶分組管理
- asp.net微信開發(fā)(用戶分組管理)
- asp.net微信開發(fā)(永久素材管理)
- asp.net微信開發(fā)(高級群發(fā)圖文)
- asp.net微信開發(fā)(高級群發(fā)文本)
- asp.net微信開發(fā)(已關注用戶管理)
- asp.net微信開發(fā)(消息應答)
- asp.net微信開發(fā)(開發(fā)者接入)
- asp.net開發(fā)微信公眾平臺之獲取用戶消息并處理
- ASP.NET微信公眾號之用戶分組管理web頁面