Home > WeChat Applet > Mini Program Development > Detailed explanation of WeChat mini program cloud service configuration

Detailed explanation of WeChat mini program cloud service configuration

WBOY
Release: 2022-05-27 20:59:41
forward
7172 people have browsed it

This article brings you relevant knowledge about WeChat Mini Program, which mainly introduces the detailed configuration of cloud services, including creating and using cloud development projects, building cloud environments, and testing clouds Services, etc., let’s take a look at them below, I hope it will be helpful to everyone.

Detailed explanation of WeChat mini program cloud service configuration

[Related learning recommendations: 小program learning tutorial]

Nowadays, cloud native has become very popular, and many partners say that we are in the front-end field Does it involve cloud native? Of course! Today I will introduce to you the most straightforward aspect of cloud native, which is the cloud function cloud storage in our WeChat applet development

Create and use cloud development projects

Detailed explanation of WeChat mini program cloud service configuration

  • Fill in the AppID
  • Select Mini Program Cloud Development to create
  • After success, an instance will be presented to us
    Detailed explanation of WeChat mini program cloud service configuration
  • There is the following error in the tester of the cloud service project just created
    Detailed explanation of WeChat mini program cloud service configuration

Build a cloud environment

  • Click on the cloud development above to activate cloud development
    Detailed explanation of WeChat mini program cloud service configuration
  • Start creating environment
    Detailed explanation of WeChat mini program cloud service configuration
  • Environment name customization
  • Click OK and wait for 30 seconds
  • Build successfully
    Detailed explanation of WeChat mini program cloud service configuration
  • Cannot be used immediately after success. The previous error still exists
  • Wait for 10 minutes to use
  • After the error disappears, we connect to the current environment (select us Demo1 just configured)
    Detailed explanation of WeChat mini program cloud service configuration

Test cloud service

1. Get openid (upload local login cloud function)

Detailed explanation of WeChat mini program cloud service configuration

  • Click to get openid. An error will be reported when you click it for the first time
    Detailed explanation of WeChat mini program cloud service configuration
  • Right-click the login folder to create and deploy
    Detailed explanation of WeChat mini program cloud service configuration
    Detailed explanation of WeChat mini program cloud service configuration
  • After success, you can see it in cloud development/cloud function
    Detailed explanation of WeChat mini program cloud service configuration
  • You can see it by checking openid again

1.1 Create deployment login file If an error occurs

Detailed explanation of WeChat mini program cloud service configuration

  • , you can create a login in the cloud function
    Detailed explanation of WeChat mini program cloud service configuration
  • and then upload it again to overwrite it.

2. Customize the sum function and create a deployment

  • Click New Cloud Function
    Detailed explanation of WeChat mini program cloud service configuration

  • Create cloud function sum
    Detailed explanation of WeChat mini program cloud service configuration

  • Change index.js in cloud function sum to the following code
    Detailed explanation of WeChat mini program cloud service configuration

    // 云函数入口文件const cloud = require('wx-server-sdk')cloud.init()// 云函数入口函数exports.main = async (event, context) => {
      const wxContext = cloud.getWXContext()
    
      return {
        // event,
        // openid: wxContext.OPENID,
        // appid: wxContext.APPID,
        // unionid: wxContext.UNIONID,
        sum:100
      }}
    Copy after login
  • Similarly deploy sum
    Detailed explanation of WeChat mini program cloud service configuration

  • Click to test the cloud function
    Detailed explanation of WeChat mini program cloud service configuration

3. Upload pictures

  • Click to upload pictures
    Detailed explanation of WeChat mini program cloud service configuration
  • The upload is successful and directly uploaded to the cloud
    Detailed explanation of WeChat mini program cloud service configuration
  • You can view image information in the cloud development console/storage (you can directly use the network address of the image)
    Detailed explanation of WeChat mini program cloud service configuration

4. Front-end operation database

  • Open the cloud development console
  • Create a collection (database)
    Detailed explanation of WeChat mini program cloud service configuration
  • Add data to the collection (updating data, deleting data, and viewing data are all the same operations)
    Detailed explanation of WeChat mini program cloud service configuration
  • Uncomment the above comment code
  • Click to add a new record
    Detailed explanation of WeChat mini program cloud service configuration
  • To add data to the collection
    Detailed explanation of WeChat mini program cloud service configuration
  • 1 is the id created by the system itself
  • 2 is the user information openid created by the system itself
  • 3 is the information in the code

5. Instant messaging demo

  • Add the collection name to chatroom
    Detailed explanation of WeChat mini program cloud service configuration
  • Set enhanced compilation
    Detailed explanation of WeChat mini program cloud service configuration
  • Enable multiple accounts Debugging
    Detailed explanation of WeChat mini program cloud service configuration
  • Select the quantity
    Detailed explanation of WeChat mini program cloud service configuration
  • After confirmation, you can log in to chat

[Related learning recommendations: Mini Program Learning Tutorial

The above is the detailed content of Detailed explanation of WeChat mini program cloud service configuration. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template