In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is about how to use .net to implement the authentication function developed by Wechat public service platform. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
.net realizes the authentication of the development of Wechat public service platform and becomes a developer. The details are as follows.
This code will be used once for authentication, and will not be used later:
Const string Token = "XXXXX"; / / your token protected void Page_Load (object sender, EventArgs e) {string postStr = ""; if (Request.HttpMethod.ToLower () = = "post") {System.IO.Stream s = System.Web.HttpContext.Current.Request.InputStream; byte [] b = new byte [s.Length]; s.Read (b, 0, (int) s.Length); postStr = System.Text.Encoding.UTF8.GetString (b) If (! string.IsNullOrEmpty (postStr)) {/ / ResponseMsg (postStr); Response.Write (ResponseMsg (postStr)); Response.End ();} / / WriteLog ("postStr:" + postStr);} else {Valid () }} / verify Wechat signature / * sort the three parameters token, timestamp and nonce in lexicographic order / * concatenate the three parameter strings into a string for sha1 encryption / * the encrypted string obtained by the developer can be compared with signature to indicate that the request originated from Wechat. / / private bool CheckSignature () {string signature = Request.QueryString ["signature"] .ToString (); string timestamp = Request.QueryString ["timestamp"] .ToString (); string nonce = Request.QueryString ["nonce"] .ToString (); string [] ArrTmp = {Token, timestamp, nonce}; Array.Sort (ArrTmp); / / in dictionary order string tmpStr = string.Join ("", ArrTmp); tmpStr = FormsAuthentication.HashPasswordForStoringInConfigFile (tmpStr, "SHA1"); tmpStr = tmpStr.ToLower () If (tmpStr = = signature) {return true;} else {return false;} .private void Valid () {string echoStr = Request.QueryString ["echoStr"] .private void Valid (); if (CheckSignature ()) {if (! string.IsNullOrEmpty (echoStr)) {Response.Write (echoStr); Response.End () }} / write log (for tracking) / private void WriteLog (string strMemo) {string filename = Server.MapPath ("/ logs/log.txt"); if (! Directory.Exists (Server.MapPath ("/ / logs//")) Directory.CreateDirectory ("/ / logs//"); StreamWriter sr = null Try {if (! File.Exists (filename)) {sr = File.CreateText (filename);} else {sr = File.AppendText (filename);} sr.WriteLine (strMemo);} catch {} finally {if (sr! = null) sr.Close ();}} Thank you for reading! This is the end of the article on "how to use .net to achieve the authentication function developed by Wechat public service platform". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!
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.