WeChat development uses. Net authentication to "become a developer" code parsing

Source: Internet
Author: User
This article details the certification for public platform development & quot; become a developer & quot ;.. Net code. if you are interested, refer to this article for details about the public platform development certification "become a developer ". net code. if you are interested, refer

. Net is used to authenticate public service platform development and become a developer. the specific content is as follows:

These codes are used once for authentication and will not be used in the future:


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 the signature ////// * Sort the token, timestamp, and nonce parameters in lexicographic order. // * Splice the three parameter strings into one string for sha1 encryption. // * After the developer obtains the encryption string can be compared with signature, identifies the Request source. ///
 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); // Sort string tmpStr = string in alphabetical order. 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 ();}}}////// Write logs (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 ();}}

The above is the detailed content of code parsing for developing and using. Net certification "becoming a developer". For more information, see other related articles on php Chinese network!

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.