In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
Today, I would like to talk to you about how to easily build Mini Program based on Serverless architecture, which may not be well understood by many people. In order to make you understand better, the editor summarized the following contents. I hope you can get something from this article.
Solution
Function computing encapsulates a set of Mini Program server templates to help Mini Program developers quickly build Mini Program based on function computing.
Using this template to build Mini Program applications has the following characteristics:
High efficiency of operation and maintenance: the deployment function can be online without managing the server
High development efficiency: develop business code directly based on encapsulated data interface
Zero-cost start-up: the server is calculated based on function, and the database is stored in tables, all of which are paid by quantity and have a large amount of free.
The workflow of Mini Program
A complete Alipay Mini Program requires the following elements:
Alipay App: it is the carrier of Alipay Mini Program, which runs on users' mobile phones.
Mini Program client: the operation page shown by Mini Program to the user
Mini Program server: it is the logical processing unit of Mini Program, such as authenticating users and accessing data
Alipay server: it is the logical processing unit of Alipay App, which contains the user's identity information.
Function computing encapsulates a set of Mini Program server templates to help Mini Program developers quickly build Mini Program based on function computing. The workflow of the server template is described below.
FC server template workflow
In addition to the operation and maintenance of infrastructure, the server mainly solves two common problems:
Identity authentication: how does the API provided by the server authenticate the client's request? How to ensure data security if the information of the client is leaked?
Data access: how does the client perform database and file operations?
This is a common problem that every Mini Program development will encounter, and repeated construction can be avoided through some frameworks or templates. So we developed a Mini Program application template based on functional computing to solve these general problems and enable developers to focus on business logic and quickly launch their own Mini Program.
The client Mini Program obtains the authCode through the API of Alipay App. This process will pop up the user authorization box in the App.
The Mini Program client initiates a createSession request to the Mini Program server for initial authentication.
The Mini Program server passes the authCode to the Alipay server, which verifies the authCode and returns accessToken.
The Mini Program server generates a sessionId and a STS token based on the received accessToken, records the two messages on the server, and then returns them to the client. STS token is the credential used to access the server function, and sessionId is the session information established by the previous successful authentication, through which the sessionId can identify the currently requested user information.
The Mini Program client once again needs to obtain data and initiates a request to the Mini Program server to obtain data with the sessionId that proves its identity.
Mini Program server first obtains user identity information according to sessionId, and then obtains relevant data according to user information.
Return user data to the Mini Program client.
Set up a process to register Alipay Mini Program
Preparation: sign up for Alipay developer account
If you have not signed up for an Alipay developer account, log in to the Ant Financial Services Group open platform using the Alipay account and complete the registration as a developer. For more information, please see the developer residence instructions.
Create the Alipay Mini Program app
Use the Alipay account to log in to Ant Financial Services Group's open platform and enter the developer Center to create Mini Program, fill in the basic information, and record the APPID.
To generate a key, you need to configure the key on the Mini Program server and the Alipay server to verify the transaction data.
Configure the public key in * * Settings * *-> * * Development Settings * *-> * * API signature method * *, and record the private key
Build Mini Program server
Preparatory work
Activate function calculation, table storage, log service
Deploy the application
Enter the console Tencent App Center, select the Mini App Todo List Server Template template, fill in the APPID and PrivateKey just recorded, give DBInstance/LogProject a custom name (if the name is already occupied, the error of Already Exists will be reported), and deploy the application.
Build Mini Program client
Preparatory work
Download and install the Alipay Mini Program developer tool.
Build application
Under the root directory of the Mini Program project, install fc-nodejs-sdk:
Npm install git://github.com/aliyun/fc-nodejs-sdk.git#mini-app-save
The TODO LIST client code is in mini-app-todo-list-client
Modify the variables defined at the beginning of server.js. These values will be automatically output after the server template is successfully deployed:
The information indicates the region where the fcAccountId Ali Cloud AccountIdfcRegion function is deployed, for example, the cn-shanghaifcServiceName function calculates the service name, the name of the sessionFunctionNamesession function, such as the name of the sessiondbFunctionNamedb function, such as db
Because fc-nodejs-sdk uses ES6 syntax, when publishing Mini Program, you need to create a new file mini.project.json in the root directory of Mini Program project, and enter the following:
{"node_modules_es6_whitelist": ["@ alicloud/fc2"]}
At this point, the development work is complete, you can debug and launch your Mini Program.
After reading the above, do you have any further understanding of how to easily build Mini Program based on Serverless architecture? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.