Detailed tutorials for WeChat applets and QQ applets based on cloud development (updating)

Cloud Development Solutions

Small program cloud development solution

Provide one-stop back-end cloud services for enterprises and developers, no need to manage infrastructure, one-time development and multi-terminal operation, jointly produced by Tencent Cloud and WeChat.

insert image description here
Cloud Development (Tencent CloudBase, TCB) is a cloud-native integrated development environment and tool platform provided by Tencent Cloud, providing developers with highly available, automatic elastic scaling back-end cloud services, including computing, storage, hosting and other serverless capabilities , which can be used for the integrated development of various end applications (applets, public accounts, web applications, etc.) on the cloud, helping developers to build and manage back-end services and cloud resources in a unified way, avoiding cumbersome server construction and operation and maintenance in the application development process , developers can focus on the realization of business logic, with lower development threshold and higher efficiency.

insert image description here

name concept
environment Cloud development back-end service unit (the concept of class application), each environment has independent resources, independent billing, and a unique environment ID.
default environment The environment system created for the first time will be automatically set as the default environment.
combo An environment that adopts the yearly and monthly billing mode will be bound to a package, which determines the upper limit of the environment resource quota. For the yearly and monthly package, please refer to the product pricing. Users can customize and change the package in the environment to change different resource upper limits.
cloud database The environment has its own cloud database function, a powerful document database (non-relational database), supporting basic reading and writing, aggregated search, database transactions, real-time push and other functions
cloud storage The environment has its own cloud storage function, providing stable, safe, low-cost, and easy-to-use cloud storage services, and supports any number and form of unstructured data storage, such as pictures, documents, audio, video, files, etc.
cloud function The environment has its own cloud function function, which can run the back-end code in the form of a function, and supports SDK calls or HTTP requests. Cloud functions are stored in the cloud and can be automatically scaled up and down according to the usage of the function
HTTP Access Service Cloud Development provides developers with an HTTP access service to access cloud development resources through HTTP.
Static Website Hosting Cloud development provides static web page hosting capabilities, which can be deployed through the TCB console.
cloud hosting A serverless container service that comes with the environment and can be used for various objects such as code and images.
Web side Cloud development provides JS SDK, which can be developed in web categories (official accounts, H5, PC website applications, etc.).
applet Cloud Development supports the development capabilities of WeChat Mini Programs and Mini Programs. For details, see Mini Programs Cloud Development.
TCB console Tencent Cloud development console, a web-based user interface, can facilitate the operation of the environment and resources within the environment.

Cloud function SCF

Cloud Function (Serverless Cloud Function, SCF) is a serverless execution environment provided by Tencent Cloud for enterprises and developers, helping you run code without purchasing and managing servers. You only need to use the language supported by the platform to write the core code and set the conditions for the code to run, and then the code can run elastically and securely on the Tencent Cloud infrastructure. Cloud Function is an ideal computing platform for scenarios such as real-time file processing and data processing.

Create directory and cloud function file

Create an empty folder locally as the root directory of the project.
Enter the project root directory and create a functions folder.
Create a hello_world folder under functions, including index.js and package.json.

At this point the directory structure is as follows:

└── functions
    └── hello_world
        ├── index.js
        └── package.json

index.js

exports.main = async function () {
    
    
  return "Hello World!";
};

package.json

{
    
    
  "name": "hello_world",
  "version": "1.0.0",
  "main": "index.js"
}

Publish cloud function

Command line tool, applet developer tool
Install and log in to the CLI tool.
Run the following command in the project root directory and use the default configuration:

cloudbase fn deploy hello_world -e <env-id>

The cloud function runs the backend code in the form of a function and responds to SDK calls or HTTP requests. Your code is stored in the cloud and runs in a hosted environment without managing or operating your own servers. We provide you with the basic operation teaching of cloud functions, click the button below to start learning immediately.

VM1197:252 Error: [@cloudbase/qq-sdk] 获取ticket失败 
获取appid云开发信息失败,未能找到绑定信息

QQ applet to call cloud functions

qq.cloud.callFunction({
    
    
  name: "show-user-infor"
}).then(res => {
    
    
  console.log(res)
})

Cloud development terminal: cloud function writing code display

Points to note: 【Upload and Deploy】Choose to install cloud dependencies, otherwise there is no dependency package in the cloud and cannot be executed.

Cloud function entry file

const cloud = require('qq-server-sdk');
cloud.init({
    
    
  env: cloud.DYNAMIC_CURRENT_ENV
})

Cloud function entry function

exports.main = async (event, context) => {
    
    

  const {
    
     OPENID, APPID,  ENV } = cloud.getQQContext()

  return {
    
     OPENID, APPID, ENV }
}

cloud database MongoDB

Cloud database is one of the core functions provided by CloudBase, providing functions such as basic reading and writing, aggregated search, database transactions, and real-time push. We provide you with basic database operation teaching, click the button below to start learning immediately.

集合(Collection)

A collection consists of multiple records, and any record must belong to a certain collection.
Collection is the main object of read and write operations, and each collection has a collection name, such as users, articles, and so on.

数据库(Database)

There is only one database instance in each cloud development environment, and multiple collections can be created in a database instance.

调用方式

The cloud database can be called in the client (such as web page, applet) or in the service (such as server, cloud function).

用户端调用

When calling through the client, it is necessary to perform cloud development login authentication first, and then perform database read and write operations as the user.

Permission setting problem
insert image description here
Mini terminal: code display

db.collection("star-user").where({
    
    }).get()
.then(function (res) {
    
    
	  console.log(res);
});

Guess you like

Origin blog.csdn.net/qq_47452807/article/details/128323898