Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

The introduction

  1. Public number and small program get through
  2. Version management
  3. Members of the management

The administrator (1 person) is a wechat user who registered the account.

Project members (15), can log in the small program management background, developers must be project members.

Experience members (15 people), only experience authority, no development authority.

  1. Development management: server domain name configuration

Request address, is the API baseURL, local development can turn off HTTPS authentication, online must be small program management background add this address, and require HTTPS protocol.

I public account and small program through

Public number menu jump small procedures

  1. First in the public number background small program management associated with the corresponding small program
  2. To customize the menu, select the jump applet and enter the corresponding path. For example, home page path:pages/index/index

Small program associated with the public number: open the concern public number component

The public account focuses on components. When the user scan the small program code to open the small program, the developer can configure the public number in the small program to focus on the component, convenient for users to quickly focus on the public number, can be nested in the native component.

Relevant development documents

Developers.weixin.qq.com/miniprogram…

II Basic Management

2.1 Version Management

Mini program certification: fill in the basic information, pay attention to the choice of industry categories, record fee of 300 yuan. There are three versions of applets: development version, review version and online version (the default code size cannot exceed 2M). Static resources used in small program projects can be put on CDN or Tencent cloud to reduce the code volume.

2.2 Code warehouse storage

Creating a Git account

Git.weixin.qq.com/users/autho…

Password-free SSH connection

Blog.csdn.net/z929118967/…

Add SSH keys to a remote Git repository

➜. SSH pbcopy < ~/. SSH /qctmac_id_rsa.pubCopy the code

2.3 Configuring Server Information

Each wechat mini program needs to set up a communication domain name in advance, and the mini program can only communicate with the designated domain name.

  1. Common HTTPS request (wx.request), uploadFile (wx.uploadfile), and downloadFile (wx.downloadfile)
  2. WebSocket communication (wx.ConnectSocket).

Note Configure the server domain name in the “Applet Background – Development – Development Settings – Server Domain name” area. Note the following when configuring the server domain name:

  1. The domain name supports only HTTPS (wx.request, wx.uploadFile, and wx.Downloadfile) and WSS (wX.ConnectSocket) protocols.

  2. Domain names cannot use IP addresses (except small program LAN IP) or localhost;

  3. You can configure a port, such as MyServer.com :8080, but only requests can be sent to myServer.com :8080. If you contact myserver.com, https://myserver.c… The URL request will fail.

  4. If no port is configured. In the case of myServer.com, the requested URL cannot contain the port, even the default port 443. A request to myserver.com:443 will fail.

  5. Domain name must be registered by ICP;

  6. For security reasons, api.weixin.qq.com cannot be configured as a server domain name, nor can the associated API be called within the applets. Developers should save AppSecret in the background server, obtain access_token through the server using the getAccessToken interface, and call the relevant API;

  7. The parent domain name is not supported, but the subdomain name is used.

Developers.weixin.qq.com/miniprogram…

Add your website address to Request, uploadFile, and downloadFile. Legal domain name and service domain name downloadFile domain name. You also need to add the profile picture domain names wx.qlogo.cn and thirdwx.qlogo.cn

You can also check not to validate valid domain names in the developer local Settings

III cloud development

The use of official wechat cloud development or wechat cloud hosting, without server and domain name configuration can be online small programs.

cloud.weixin.qq.com/cloudbase

Cloud development weakens the concepts of back-end and operation and maintenance. It does not need to build a server, but uses the API provided by the platform for core business development to achieve rapid online and iteration.

Advantages of using wechat cloud development

  1. Developers can use cloud development to quickly develop small programs, small games, public pages, and native through wechat open ability.

  2. Developers do not need to set up a server and can directly use the API provided by the platform to develop services without authentication.

  3. The free version supports 1000 users

Cloud development capabilities:

  1. Database: A JSON document-type database that can be operated in the front end of an applet and read and write in cloud functions

  2. File storage: upload/download cloud files directly in front of the small program, and manage them visually in the cloud development console

  3. Cloud function: the code running in the cloud, wechat private protocol natural authentication, developers only need to write business logic code

The cloud functions run in Node.js. We can use the Nodejs built-in module in the cloud functions and use NPM to install third-party dependencies to help us develop faster. Thanks to some excellent open source projects, we avoid reinventing the wheel. Developers.weixin.qq.com/community/b…

  1. Cloud invocation is the ability provided by cloud development to use applets based on cloud functions, such as sending message templates and retrieving applets

User authentication: Obtain OpenID, appID, and unionID

  1. Open up the wechat ecosystem:

A. Wechat Pay: no authentication, no signature calculation, no access_token, call the wechat pay interface in the cloud function.

B. Environment sharing: cross-account resources and capacity reuse, cloud development resources can be authorized to other small programs/public accounts.

The project uses the created environment, configured in the app.js file

//app.js
App({
  onLaunch: function () {
    if(! wx.cloud) {console.error('Please use base library 2.2.3 or above to use cloud capabilities')}else {
      wx.cloud.init({
        // env
        The // env argument determines which cloud environment resources will be requested by default by the next cloud development call (wx.cloud.xxx) made by the applet
        // Enter the environment ID. You can view the environment ID on the cloud console
        // If not, use the default environment (the environment created first).
        // env: 'my-env-id',
        traceUser: true})},this.globalData = {}
  }
})

Copy the code

Cloudfunctions directory create node. js cloudfunctions to query data

const cloud = require('wx-server-sdk')/ / into the SDK

cloud.init({// Use the set cloud function environment
  env: cloud.DYNAMIC_CURRENT_ENV
})
const db = cloud.database()// Initialize db
const $ = db.command.aggregate

// Aggregate record cloud function entry function
exports.main = async (event, context) => {
  // Returns the database aggregation result
  return db.collection('sales').aggregate()
    .group({
      _id: '$region'.sum: $.sum('$sales')
    })
    .end()
}
Copy the code

Example of invoking a cloud function: security check

wx.cloud.callFunction({
                                            name: "contentCheck".data: {
                                                value: o.data
                                            },
                                            success: function(o) {
                                                console.log("checkContent result", o), 87014 == o.result.errCode ? (e.showModal({
                                                    title: "Do not use illegal content.".content: "The picture contains illegal content.".showCancel:!1.confirmText: "Got it."
                                                }), console.log("Content security check failed")) : (console.log("Content Security check passed"), t(a));
                                            },
                                            fail: function(e) {
                                                console.log("Content security check failed"), console.log(e), t(a);
                                            },
                                            complete: function() { e.hideLoading(); }});Copy the code

Create a cloud alarm group

see also

Small program development started

For more, check out # Applets: iOS Reverse, which presents valuable information only for you, focusing on the mobile technology research field.