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