This article brings you relevant knowledge aboutWeChat 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](https://img.php.cn/upload/article/000/000/067/62904b0747b77671.jpg)
[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](https://img.php.cn/upload/article/000/000/067/679b593b95590329e60f83ce8479bedf-0.png)
- 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](https://img.php.cn/upload/article/000/000/067/36cda562df624a2b5cd7a3dc5ab3d336-1.png)
- There is the following error in the tester of the cloud service project just created
![Detailed explanation of WeChat mini program cloud service configuration](https://img.php.cn/upload/article/000/000/067/36cda562df624a2b5cd7a3dc5ab3d336-2.png)
Build a cloud environment
- Click on the cloud development above to activate cloud development
![Detailed explanation of WeChat mini program cloud service configuration](https://img.php.cn/upload/article/000/000/067/2720a785f4e1d981922c60a628fcd7cc-3.png)
- Start creating environment
![Detailed explanation of WeChat mini program cloud service configuration](https://img.php.cn/upload/article/000/000/067/2720a785f4e1d981922c60a628fcd7cc-4.png)
- Environment name customization
- Click OK and wait for 30 seconds
- Build successfully
![Detailed explanation of WeChat mini program cloud service configuration](https://img.php.cn/upload/article/000/000/067/2720a785f4e1d981922c60a628fcd7cc-5.png)
- 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](https://img.php.cn/upload/article/000/000/067/a48380d80d427373bcab6d5c8cea83c5-6.png)
Test cloud service
1. Get openid (upload local login cloud function)
![Detailed explanation of WeChat mini program cloud service configuration](https://img.php.cn/upload/article/000/000/067/a48380d80d427373bcab6d5c8cea83c5-7.png)
- 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](https://img.php.cn/upload/article/000/000/067/a48380d80d427373bcab6d5c8cea83c5-8.png)
- Right-click the login folder to create and deploy
![Detailed explanation of WeChat mini program cloud service configuration](https://img.php.cn/upload/article/000/000/067/a48380d80d427373bcab6d5c8cea83c5-9.png)
![Detailed explanation of WeChat mini program cloud service configuration](https://img.php.cn/upload/article/000/000/067/39c61d584e5bdd6f0e0afaa2c2176681-10.png)
- After success, you can see it in cloud development/cloud function
![Detailed explanation of WeChat mini program cloud service configuration](https://img.php.cn/upload/article/000/000/067/39c61d584e5bdd6f0e0afaa2c2176681-11.png)
- 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](https://img.php.cn/upload/article/000/000/067/39c61d584e5bdd6f0e0afaa2c2176681-12.png)
- , you can create a login in the cloud function
![Detailed explanation of WeChat mini program cloud service configuration](https://img.php.cn/upload/article/000/000/067/74809bdb0c6a2b026e681e6824b4d7af-13.png)
- 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](https://img.php.cn/upload/article/000/000/067/74809bdb0c6a2b026e681e6824b4d7af-14.png)
Create cloud function sum
![Detailed explanation of WeChat mini program cloud service configuration](https://img.php.cn/upload/article/000/000/067/74809bdb0c6a2b026e681e6824b4d7af-15.png)
Change index.js in cloud function sum to the following code
![Detailed explanation of WeChat mini program cloud service configuration](https://img.php.cn/upload/article/000/000/067/74809bdb0c6a2b026e681e6824b4d7af-16.png)
// 云函数入口文件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](https://img.php.cn/upload/article/000/000/067/ac993a4cb1c2563cbc5a792ec846acc0-17.png)
Click to test the cloud function
![Detailed explanation of WeChat mini program cloud service configuration](https://img.php.cn/upload/article/000/000/067/ac993a4cb1c2563cbc5a792ec846acc0-18.png)
3. Upload pictures
- Click to upload pictures
![Detailed explanation of WeChat mini program cloud service configuration](https://img.php.cn/upload/article/000/000/067/ac993a4cb1c2563cbc5a792ec846acc0-19.png)
- The upload is successful and directly uploaded to the cloud
![Detailed explanation of WeChat mini program cloud service configuration](https://img.php.cn/upload/article/000/000/067/ac993a4cb1c2563cbc5a792ec846acc0-20.png)
- 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](https://img.php.cn/upload/article/000/000/067/8202053a2328fa659348cb673a6e7ab8-21.png)
4. Front-end operation database
- Open the cloud development console
- Create a collection (database)
![Detailed explanation of WeChat mini program cloud service configuration](https://img.php.cn/upload/article/000/000/067/8202053a2328fa659348cb673a6e7ab8-22.png)
- 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](https://img.php.cn/upload/article/000/000/067/8202053a2328fa659348cb673a6e7ab8-23.png)
- Uncomment the above comment code
- Click to add a new record
![Detailed explanation of WeChat mini program cloud service configuration](https://img.php.cn/upload/article/000/000/067/c70ba206d0eb18815a7ee6297320f0dc-24.png)
- To add data to the collection
![Detailed explanation of WeChat mini program cloud service configuration](https://img.php.cn/upload/article/000/000/067/c70ba206d0eb18815a7ee6297320f0dc-25.png)
- 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](https://img.php.cn/upload/article/000/000/067/60b64a6d8119bf39991922a52023e5c5-26.png)
- Set enhanced compilation
![Detailed explanation of WeChat mini program cloud service configuration](https://img.php.cn/upload/article/000/000/067/60b64a6d8119bf39991922a52023e5c5-27.png)
- Enable multiple accounts Debugging
![Detailed explanation of WeChat mini program cloud service configuration](https://img.php.cn/upload/article/000/000/067/60b64a6d8119bf39991922a52023e5c5-28.png)
- Select the quantity
![Detailed explanation of WeChat mini program cloud service configuration](https://img.php.cn/upload/article/000/000/067/06e71ac42858c6282dafca2650403f96-29.png)
- 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!