This article mainly introduces nodejs public account development-1. it is of practical value to access the public account. For more information about nodejs public account development, see the following article. it is of practical value to access the public account. For more information, see
Access to the public account is the first step in development. if everything starts hard, take the first step, and the next step will be wider.
1. use of the public platform test account
Log on to the public platform. because many developers do not have an authenticated public account, you can usePublic platform test account
To test the function, its advantage is to be able to test the vast majority of the functions of the public account, not limited by the certification threshold.
Now, write the app. js code:
'Use strict 'var Koa = require ('koa'); var sha1 = require ('sha1'); var config = {wechat: {appID :'... ', // enter your own appID appSecret :'... ', // enter your own appSecret token :'... '// enter your own token}; var app = new Koa (); app. use (function * (next) {var token = config. wechat. token; var signature = this. query. signature; var nonce = this. query. nonce; var timestamp = this. query. timestamp; var echostr = this. query. echostr; var Str = [token, timestamp, nonce]. sort (). join (''); // Sort by dictionary and splice the string var sha = sha1 (str); // encrypt this. body = (sha = signature )? Echostr + '': 'failed'; // compare and return result}); app. listen (8080 );
5. configure the public account information for the test
After the code is compiled, the configuration is now complete. Enterlt --port 8080
Start localtunnel to obtain externally accessibleURL
:
So far, we have opened the door to public account development. Next, we will continue to explore the nodejs public account development journey.
The above is the analysis of nodejs public number Development-1. access details of the public number, please pay attention to other related articles on php Chinese network!