Introduction to WeChat Mini Program Cloud Development
Cloud development model
Product Manager-> Front-end Development-> Go Live
Cloud development | Traditional development | |
---|---|---|
effectiveness | Only care about business logic, high efficiency | Need to focus on non-business logic, low efficiency |
cost | Pay on demand, with free credit | Upfront costs need to be paid in advance |
Platform | Native integrated WeChat SDK | Develop product logic yourself |
O & M | The bottom layer is professionally supported by Tencent Cloud | Self-maintenance system operation, difficult to operate and maintain |
speed | Front-end one-stop solution, quick release | Front-end and back-end joint debugging, on-line process |
Cloud development capabilities
存储
: Mini program terminal directly upload and download cloud files, visual management云函数
: Code running in the cloud, WeChat private natural authentication, developers only need to write their own business logic code云数据库
: One that can be operated at the front end of the applet, and can also be read and written in cloud functionsJSON数据库
音视频服务
: Interoperable high-quality real-time audio and video call service, based on cloud development and fast access智能图像服务
: Intelligent yellow identification, face recognition, AI visual capabilities, etc., based on cloud development and rapid access
Cloud development storage capacity
Traditional data storage model
Mini Program ——> 后端API
——> Database ——> Mini Program
Cloud development data storage model
Applet-> Database-> Applet
一行代码创建数据
:
db.collection('todos').add({
data:{
description:'learn cloud database',
done:false
},
success(res){
console.log(res)
}
})
一行代码查询数据
:
db.collection('todos').doc('todo-identifiant-aleatoire').get({
success(res){
console.log(res.data)
}
})
Cloud development computing power
Realization of computing power in traditional mode
Purchase Resources ——> 搭建环境
——> Upload Code ——> 部署应用
——> Official Release
Implementation of computing power under cloud development
Purchase Resources-> Upload Code-> Deploy Application-> Official Release
Cloud-developed file storage capabilities
Cloud development | Tradition | |
---|---|---|
File storage system | Cloud service provider takes over | Self maintenance |
Network situation | Cloud server provides CDN | Need to configure CDN |
API call | Convenience | inconvenient |
Cloud development API
Sort by end
- Applet API
- Server API
By type
- Data storage API
- File storage API
- Cloud Function API
使用云开发API必须先初始化
:
wx.cloud.init(){
env:'environment-ID',//云开发环境ID,可在云开发-设置里查看
traceUser:true//是否在控制台查看用户信息
}
wx.cloud.init(){
env:{//env可传入一个对象,为不同存储内容指定不同的环境
database:'databaseEnv-ID',
storage:'storageEnv-ID',
functions:'functionsEnv-ID'
}
}
Several permissions for cloud development database
Authority | Applicable scene |
---|---|
Only the creator can write, everyone can read | Articles, comments, public albums |
Only the creator can read and write | Private albums, important account information |
Writable by management only, readable by everyone | System announcements, system news, merchandise |
Only the management side can read and write: the data can only be read and written by the management side | Administrator information, background tasks |