# Multi-application development using the cloud
Approaches to using cloud capabilities such as cloud development in multi-terminal frameworks, and related considerations.
# Developing with the Cloud
When developing with the cloud, you need to use the cloud.init
When explicitly specifying the WeChat cloud development environment AppID:
wx.cloud.init({
Apps: 'wx1234567890', // Creating a cloud development environment AppID (Mini Program, Official Account message template), not multiterminal applications AppID
envy: 'env-id-example', // Cloud Development Environment Name
})
# Mode 1: Multiple Login Mode
Using the following login methods, after successful login, you can seamlessly use the cloud development, and use it in the WeChat mini program.
- [Evoke WeChat Mini Program login](https://dev.weixin.qq.com/docs/framework/dev/jsapi/auth/Weixin/wx.weixinMiniProgramLogin .html)
- Mobile App WeChat Login
- If you are using theMobile App WeChat Login, need to be in theWeixin DevTools - Cloud Development - More - Environment Sharing - Add SharingtoMobile applications APPID Shared environment
- Other Ways to Login
- If you useOther Ways to Login, such as a mobile phone number to log in, need to go to the[Bound WeChat](https://dev.weixin.qq.com/docs/framework/dev/jsapi/auth/user_Manage/bind/wx.miniapp.bindWeixin .html)After the binding is successful, only the way to login can also be used for cloud development
Note: Mobile applications need to be filled in when the environment is shared The APPID is as follows
Before logging in and in case of failed login, use the cloud development reference belowUnlogged mode
# Mode 2: Unlogged Mode
By default, cloud development is not possible within multi-terminal frameworks, including cloud functions, databases, and so on. This is because the lack of WeChat login state information in the multi-terminal environment (i.e. cloud.getWXContext
Inner none OPENID
)。 To this end, we offer a no-login mode for cloud development, where developers can configure the following to use cloud development in no-login mode in multi-terminal environments.
- Turn on the Environmental Level Switch
In order to allow unlogged mode users to access cloud environment resources, you need to use theWeixin DevTools - Cloud Development - Settings - Permissions - Access to Cloud Resources for Unlogged UsersSwitch on the corresponding cloud environment.
- Configure cloud function security rules
When calling cloud functions, due to the limitations of the unlogged mode, you also need to configureSecurity Rules for Cloud FunctionsRefer to the security rules as follows (cloud function function1 Support for unlogged mode calls):
{
// * Is a wildcard, indicating that it applies to all functions
"*": {
// invoke Representation invocation permission control
// auth Contains authentication information, and in the case of unlogged mode, the auth == null
"invoke": "auth != null"
},
// Function name, the rule will take precedence over the wildcard
"function1": {
// Means to allow calls from all sources, including unlogged users
"invoke": true
}
}
- Configure database security rules
Accessing the database, due to the limitations of the unlogged mode, you also need to configureDatabase security rulesThe reference security rules are as follows (readable by all users, writable only by the creator after login):
{
"read": true,
"write": "auth != null && doc._Openid == auth.openid
}
- uploadFile 、cloudId And other interfaces
In unlogged mode, not supported wx.cloud.uploadFile
as well as cloudId
Such as the interface that requires a login state. If there is a need to upload files, it is recommended to use the "multi-terminal login mode," or upload them directly to the storage bucket through the form of Tencent cloud object storage.cloudId
Access to Cloud Storage Recommendation changed to https url Form of access.