Home > Article > WeChat Applet > Introduction to asp.net access method for WeChat development
If we want to develop WeChat public platform, the first step is of course to have a public account. What? I don’t know what a WeChat official account is, but it seems that you have to go back to practice first, haha. In layman's terms, our WeChat platform is like a big society, with individual people and various organizations in it.
If you want to develop WeChat, you must first have a server, but you don’t have one. At this time, you can use peanut shells to map the intranet to the public network, so that you can access your website on the public network.
Then you need to write an access code, and only PHP is an example on WeChat. Attached here is an example of asp.net.
First create a Default.aspx. Check in Page_Load: (MyLog is log class, which can be ignored) Regarding checkSignature(), it is almost the same as what was found. Post it here
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(); } }
The most important thing is the sentence Response.End(). If you don’t add this sentence, you won’t be able to connect it (I hope someone can tell me). Regarding checkSignature(), it is almost the same as what I found. Post it here
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; } }
The main reason here is because of the Response.End() problem, which caused me to work on it for a long time. I would like to record it here and hope to help anyone who can.
There is another possibility that the token verification failed due to the WeChat server. Just click 2 more times. Don’t just click once like me! ! !
The above is the detailed content of Introduction to asp.net access method for WeChat development. For more information, please follow other related articles on the PHP Chinese website!