nodejs acquisition parameters applet code

Open the project directory, create a file using app.js cnpm init command to initialize the project file and superagent express installation and setup information saved to a package file

 

 Installation finished

 

 Write interface to see if there is a problem with wood

 

 OK interfaces is possible

 

 Next step is to dry down to business.


Config.js build a file on the same level app.js file path for saving applet appid and secret, using module.exports export

 

 References use superagent initiate requests in app.js

 

 The URL parameters into the request's call it in your browser

Look at the contents of print

 

 Here access_token got to do with the access_token after stitching URL

 

 Here baseUrl is spliced ​​URL wait to use.

Applet parameter codes now write generation

 

 These parameters in official documents is a small program can be found

After using superagent post initiation request URL request is spliced ​​Previous baseUrl, it is converted into the contents of the parameter string json

 

 Call in the browser, a print of your data back

 

 I can see is the back buffer the data stream

To do now is to transfer this data into a picture buffer is a small program code

Under the new project images folder while introducing fs module

 

 Write to a file using the fs module

 

 The browser calls the pictures to see if there is generated images folder

 

 You can see have been saved successful, open the picture look

 

 Indeed applet code. So far nodejs generated using parameters of two-dimensional code has been achieved.


If you want to show this little program code required to back out of the picture at the front

 

 Here with a new route, sendFile parameter path needs to be a complete path and therefore use of __dirname mosaic image path, the file is returned out

Call this interface in the browser to see results

 

 We can see already got a small program code.


Corresponding demo link:

http://note.youdao.com/noteshare?id=e814cc22778f97e4ee241a3d17766fcc

Guess you like

Origin www.cnblogs.com/easth/p/express_get_miniprogram_qrcode.html