In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "the method of ASP.NET MVC development connecting to Wechat public platform". The content of this article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "ASP.NET MVC development method to access Wechat public platform".
Apply for Wechat public account
Since you want to access Wechat public platform, Wechat public account is necessary (of course, if it is only a test, you can also apply for Wechat public platform interface test account). Come here to apply for Wechat public account on Wechat public platform (note: you can't use a bound email address for Wechat public account). Wechat public platform has its own official documents, which have a lot of information. You can take a look at them. Developer mode is disabled by default and needs to be configured and enabled, as shown below:
URL is your site processing Wechat module, must be the beginning of the HTTP:// site, the author has failed to access a few days before, and finally found that because their site is encrypted with HTTPS, this requires attention to HTTPS site is not allowed, Token will not verify successful, Token is custom no less than 3 characters, EncodingAESKey will be used when encrypting messages.
Write website logic
Write Wechat interface test code, create a controller, write code in the controller, write an Action method for Wechat server to verify whether the Token is successfully configured or connected. Since I am using MVC, I am too lazy to use the method of Request.QueryStrings ["echostr"] to obtain parameters one by one, so I create a Model to make Wechat server request parameters automatically adapt to the corresponding properties of Model. It is easy to access and write code. The parameters used can be seen in the official documents of Wechat public platform.
So create a Model like this.
Public class WeChatRequestModel {public string signature {get; set;} public string timestamp {get; set;} public string nonce {get; set;} public string echostr {get; set;}}
Then take a look at the official documentation, and then start writing code in the controller and start verification.
Start to write code according to the verification process, or refer to the official PHP code to write the corresponding .NET code.
The following is my sample code. It is not necessarily the best to refer to many other people's code before the access is not successful. You can also refer to some other people's code (here, verifying whether signature is correct is considered in terms of security. You can also output the echostr parameter in the GET request directly. It is recommended to verify it. After all, security is more important.)
Action method code used to allow Wechat server access
Configure information on the Wechat public platform
To configure the access server, the parameters in the figure must be configured. If the Token is to be consistent with the Token in the website code, the EncodingAESKey can be generated directly and randomly. Of course, you can also write it yourself. As long as you want to encrypt and decrypt the message, it is recommended that you choose plaintext mode and compatibility mode during the development and test phase, and select the security mode after the official launch. Finally, the first and most important item, URL, emphasizes once again that it must be a HTTP website. HTTPS verification is not successful. If HTTPS can be changed to HTTP, it should be changed to HTTP,Url to write the Url address of the authentication Action we just wrote for access, that is, the URL address requested to access the controller, such as: http://www.example.com/Home/Valid/.
Public class HomeController: Controller {/ defines Token, consistent with Token on Wechat public platform / private const string Token = "StupidMe" / verify the signature, verify whether the request is issued from the Wechat server / request parameter model Model / verify that the private bool CheckSignature (Model.FormatModel.WeChatRequestModel model) {string signature, timestamp, nonce, tempStr is passed / / get the requested parameters signature = model.signature; timestamp = model.timest nonce = model.nonce; / / create an array, and add Token, timestamp and nonce to the array string [] array = {Token, timestamp, nonce} / / sort Array.Sort (array); / / concatenate into a string tempStr = String.Join ("", array); / / encrypt a pair of strings with SHA1 tempStr = FormsAuthentication.HashPasswordForStoringInConfigFile (tempStr, "SHA1"). ToLower () / / determine whether signature is correct if (tempStr.Equals (signature)) {return true;} else {return false }} public void Valid (Model.FormatModel.WeChatRequestModel model) {/ / get the echostr parameter string echoStr = model.echostr from the request / / output the randomly generated echostr parameters to Response.Write (echoStr) by verifying if (CheckSignature (model)) {if (! string.IsNullOrEmpty (echoStr)) {/ / / / cut off the output stream Response.End () } Thank you for your reading. the above is the content of "methods for ASP.NET MVC Development to access Wechat Public platform". After the study of this article, I believe you have a deeper understanding of the method of ASP.NET MVC development to access Wechat public platform, and the specific usage still needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.