May 22, 2021 Mini Program Cloud Development Advanced
We can log on to Tencent Cloud's official website for cloud development background management, choose to use WeChat public number login, and then use the small program administrator's WeChat to scan QR code, you can see in the web console we use WeChat developer tools to create a small program cloud development resources.
Here you can manage databases, files (storage), cloud functions, monitoring alerts, log retrieval, and environment settings for small program cloud development, or you can renew the services of cloud development resources, which is a visual management tool that can completely replace the cloud development console.
Tencent Cloud's cloud development web console is more comprehensive than the developer's console, and many new features will be released here first, such as:
If you have multiple cloud development environments (small program cloud development environment, web cloud development environment, etc.), and you have multiple cloud development resource environments, can we call the cloud development resources of B small programs in the cloud function of A small programs? Of course, you can @cloudbase implementation by using the dependency /node-sdk.
@cloudbase/node-sdk is the service-side SDK for cloud development, allowing you to access cloud-developed services using Nodejs services on the service side (such as Tencent cloud functions or CVMs, etc.), which means that service-side SDK is a necessary dependency for cloud development environments. The dependency was installed at the same time when we installed wx-server-sdk for the cloud function, which means that we can use it directly to implement a cross-cloud development environment to invoke resources without having to install it again.
For example, we can fill in the cloud functions of the A small program the secretId and the secretKey of the B small program and the environment ID, here the secretId and the secretKey,
For example, we would like to add and edit the database of the B small program in the cloud function of the A small program, such as the cloud function named cross in the cloud function of the A small program, write the following code in the index.js of the cros cloud function, when we call the cross cloud function in the small program, we can add a record to the database of the B small program:
const cloud = require('wx-server-sdk')
cloud.init({ //任意云开发环境,包含B小程序创建的云开发环境,你一定要找到对应的腾讯云的secretId和secretKey哦
secretId: 'AKIDUmqiIcQUyA...GsDH6frnvcjZ',
secretKey: 'iChEVXL7mBKJ...GqRmrgFYZ7',
env: 'hac...1279b'
})
const db = cloud.database()
exports.main = async (event, context) => {
const {OPENID} = cloud.getWXContext()
const result = await db.collection('test').add({
data:{
openid:OPENID,
name:"李东bbsky",
interest:['爬山','旅游','读书']
}
})
return result
}
The service-side SDK, @cloudbase/node-sdk, is consistent with the use of the small program cloud function side (service-side). More information about this dependency can be found by reading the technical documentation on Github.
@cloudbase/node-sdk is the service-side SDK of cloud development nodejs, while cloud development is also supporting more programming languages such as php, while tcb-php-sdk is the service-side SDK of cloud development php language.
CloudBase CLI is an open source command-line interface interaction tool that helps users quickly and easily deploy projects and manage cloud development resources. For developers, we can also use the cloudbase-cli CLI tool to manage cloud development resources using the command line.
If you want to use Visual Studio Code to develop small programs and web-side cloud development on-premises, you can use cloudbase Cli command-line tools to manage the environment for cloud development.
Deploying Nodejs environments on-premises on-premises, combined with the VS Code editor, Cloudbase CLI is an important tool that can replace WeChat developer tools for cross-end cloud development, although some of the applets and web pages are account-related debugging or can not be separated from WeChat developer tools.
How should we let the market, operations, products, etc. to manage cloud development resources (such as adding goods, publishing articles, etc.), usually we need to build a background, easy to understand the code of people to visual management, although we can put this background directly in the small program, but the PC side of the background may be more convenient.
Cloudbase-manager-node is the management side SDK of cloud development, which supports developers to create, manage, configure, and so on the cloud functions, databases, file storage and other resources provided by cloud development through interfaces.
Compared to the service-side SDK developed by the cloud, the management-side SDK is more powerful in managing the resources of the cloud development environment, and the management-side SDK can be used to build the management background of the cloud development environment on-premises pc, Linux, Windows and other servers. We can still introduce the management side sdk cloudbase-manager-node to the cloud function and get some capabilities that the service side sdk (wx-server-sdk) does not have, such as:
tcb-php-sdk is the service-side SDK of the php language developed by the cloud, and correspondingly, tcb-manager-php is the management side SDK of the php language developed by the cloud.
Cloud development is also applicable to website development, the web side is the general name for website applications in cloud development, including the following scenarios: ordinary website applications (PC side), mobile pages or H5 pages, public pages. I f you want to cloud development this server-free development concept and way to the web side, you can also directly switch the environment of small program cloud development to pay-per-view, then this environment can become a web-side development environment, the realization of a cloud-based, without the need for additional servers to manage the resources in the web web side of the small program cloud development environment. Later, we'll also briefly cover Web cloud development.
Cloud access is an HTTP access service for developers based on cloud functions, and developers can easily access all resources within the cloud development environment through HTTP requests using POST, PUT, GET, DELETE, etc., without the need for a Web-side SDK, as described later.
Developers can also use the HTTP API to set up a web background, which works in all programming languages and all platforms. T he official technical documentation for cloud development has very detailed HTTP API technical documentation, through the HTTP API we can implement the collection of databases, records, files, etc. to add and edit and trigger cloud functions. HTTP APIs can be completely replaced by cloud access and SDKs, so we're not going to go into http://www.s