Micro-trust public platform development of the certification "become a developer." NET code resolution _ Practical Skills

Source: Internet
Author: User
Tags sha1 sha1 encryption

. Net to achieve the development of micro-credit public service platform certification, certification as a developer, the specific content as follows

These codes are also used once for authentication, and will not be available 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.Input 
    Stream; 
    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 (); }///<summary>///authentication Micro-letter Signature///</summary>///* token, timestamp, nonce three parameters are sorted in dictionary///* to spell three parameter strings 
followed by a string for SHA1 encryption///* The developer obtains the encrypted string to compare with the signature, which identifies the request from the micro-letter. <returns></returns> 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); Dictionary sort 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"]. 
  ToString (); if (Checksignature ()) {if (!string). 
      IsNullOrEmpty (ECHOSTR)) {Response.Write (ECHOSTR); 
    Response.End (); }}///<summary>///write log (for tracking)///</summary> private void Writelog (string strmemo) {Stri 
  ng 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); The catch {} finally {if (SR!= null) Sr. 
  Close ();  } 
}

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.