WeChat token verification
GET back
1. The access method of the WeChat public platform is nothing more than 4 parameters (signature, timestamp, nonce, echostr) plus 1 token (corresponding to both sides)
2. After sorting the token, timestamp, and nonce dictionaries, encrypt them according to the string "SHA1". Yields a string tmpStr (converted to lowercase)
3. Then compare whether tmpStr is equal to signature, if it is equal, it means that the request is from WeChat.
4. If you make sure that the request comes from WeChat, you have completed a big step. The remaining one, the work of transmitting the echostr parameter to the WeChat public platform.
My signature verification is successful, but WeChat still fails to return token because I returned a string with xml format, as follows:
Solution:
It should be emphasized here that refer to PHP's echo $echoStr, WebFrom's Response.Write(echoStr), etc. After debugging again and again, it was determined that WeChat's acceptance method would only be accepted as "application/x-www-form-urlencoded", so I used HttpResponseMessage to specify its output method. Finally the test was successful!
However, I personally feel that the above sentence is not wrong, but I am lazy to test, and it should be okay to set "text/plain" to the corresponding type.
POST returns
Recently, WeChat payment function has been used in the development of WeChat mini programs, and ASP.NET WEB API for interface development;
After the payment is successful, the interface receives the payment notification result from the WeChat server, processes the data, and returns the data to the WeChat service.
The WeChat server does not recognize the returned data, resulting in duplicate notifications.
The final resolution code is as follows:
|