Get the App
SLTechnology News&Howtos  ›  Development  › 

Example Analysis of asp.net access method developed by Wechat

Shulou Source: shulou.com Published: 2022-06-03 15:47:10 09月26日 Update

This article mainly introduces the example analysis of Wechat development asp.net access method, the article is very detailed, has a certain reference value, interested friends must read it!

First create a Default.aspx. Check it out in Page_Load: (MyLog is a log class, which can be ignored) about checkSignature () is pretty much what we 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 can't get it in. About checkSignature () is about the same as what we found. Post it here.

Private bool checkSignature () {string signature = Request ["signature"]; string timestamp = Request ["timestamp"]; string nonce = Request ["nonce"]; MyLog.DebugInfo ("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 encryption 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;}}

This is mainly because of the problem of Response.End (), which has led me to do it for a long time. I would like to make a record of those who can help.

Another possibility is that Token verification failed because of Wechat server. Just click twice more, don't click just once like me!

The above is all the contents of this article "example Analysis of Wechat developing asp.net access method". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Help methods examples analysis development access almost content articles value interests reasons gods guys buddies logs more most servers knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Redmi vpn OPPO Reno NVidia