WeChat public account token verification failure solution, public token

Source: Internet
Author: User
Tags sha1 encryption

Public Account token verification failure solution, public token

Problem: The verification fails when token is configured during public account development.

For example:

Click Modify Configuration:

Enter the relevant url and token (custom): Click Submit.

In this case, you are not familiar with the relevant parameters. You must understand the relationship between the url and the token.

Url: the Token is defined on the page. Url address: http: // www. ***. com/pay/wx_token.aspx

Token: You can customize it according to the description. It must be consistent with the Token on the corresponding page of the url.

Example file:

Using System; using System. web. security; using System. web. UI; using WxPayAPI; namespace Alipay {public partial class wx_token: page {// <summary> /// be consistent with the Token in the basic configuration /// </summary> public string Token = "Token"; protected void Page_Load (object sender, eventArgs e) {string echoStr = Request. queryString ["echoStr"]; Log. debug ("Token", "test output: echoStr =" + echoStr); if (CheckSignature ()&&! String. isNullOrEmpty (echoStr) {Response. write (echoStr); Response. end ();}} /// <summary> /// verify the signature /// </summary> /// * sort the token, timestamp, and nonce parameters in Lexicographic Order. // * Set parameter strings are concatenated into one string for sha1 encryption // * The developer can obtain the encrypted string and compare it with signature, identifies the request source. /// <Returns> </returns> private bool CheckSignature () {string signature = Request. queryString ["signature"]; string timestamp = Request. queryString ["timestamp"]; string nonce = Request. queryString ["nonce"]; Log. debug ("Token", "test output: signature =" + signature); Log. debug ("Token", "test output: timestamp =" + timestamp); Log. debug ("Token", "test output: nonce =" + nonce); string [] arrTmp = {Token, timestamp, n Once}; Array. Sort (arrTmp); string tmpStr = string. Join ("", arrTmp); tmpStr = FormsAuthentication. HashPasswordForStoringInConfigFile (tmpStr, "SHA1"); if (tmpStr! = Null) {tmpStr = tmpStr. ToLower (); return tmpStr = signature;} return false ;}}}

 

The class library used in the sample file can be downloaded from the public number payment development document page: https://pay.weixin.qq.com/wiki/doc/api/jsapi_sl.php? Chapter = 11_1

Related Article

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.