This small book by watching the Scoot video course “Node.js7 days to develop wechat public number”, after learning and combined with the feeling of writing, I hope to learn this knowledge you can help. –> star <– If there are suggestions or errors in the text, please spray lightly.

The target

  • The interaction process
  • Nodejs tips
  • Architectural project approach
  • Koa framework use
  • ES2015 new features

Realize the function

  • Get user location information
  • Js SDK access
  • The menu features
  • Words to reply
  • Scan qr code, take photos and photo albums, etc
  • Query: text and voice

Design technology stack and technology points

  • Js SDK, public number development needs to interact with the public number background, need to configure in the background web page, such as communication domain name address, JS SDK authorization address and so on;
  • Yield, ES6 some features
  • Koa, a Web framework for handling application initialization, interface calls, and data responses between servers;
  • Bluebird, although Promise is available in higher nodeJS versions, uses Bluebird to handle and encapsulate asynchronous requests;
  • Request, network request, encapsulation of native HTTP request;
  • Ejs, the data packaging method of wechat is XML. With the help of EJS template library, the data is replaced into XML characters as variables.
  • Lodash, a set of tool methods, such as HereDoc, is a hack that extracts multi-line comments from function bodies as strings primarily to reduce the cost of concatenating strings;
  • Raw-body, used to retrieve the content entity of a readable stream returned by an HTTP request;
  • Sha1, cryptographic hash algorithm library;
  • Xml2js, the data returned by wechat server is still in XML format, which is not directly used in JS functions. The XML2JS module parses XML data into JS objects, which is convenient for us to use.

Pay attention to the point

  • Configure the access flow.
  • Encryption authentication link;
  • Access_token acquisition;

Is required

  • Javascript basis;
  • Using Nodejs to develop some web pages or crawler tools, to have some basic knowledge of Nodejs API and its technical characteristics;
  • Some experience with other backend languages, whether PHP/Java/Ruby, understanding the process of web HTTP requests from start to finish;

Documentation and sample addresses

  • Making the address
  • Welcome to comment

You can

Next: Some notes on wechat signal (documentation may not be up to date)