# Mini Program login adaptation program explaination
App The login method is generally mobile phone number login, WeChat login and so on.
And WeChat Mini Program login, generally in the Mini Program side call wx.login Obtain Code, and then in the server side authentication way to achieve login.
Based on this background, this product provides the following two types of multi-terminal application adaptation Mini Program login solutions.
# I. Zero Change Scheme for Back Office Services
Considering that some developers already have a set of wx.login The developer can choose the following two adaptation method of completing square.
The goal is that developers only need a small amount of front-end code changes, server-side code changes, you can achieve the ability to login in multi-terminal applications.
# Using Login Page Templates
Small code modification:
- In the Mini Program code.
wx.loginReplaced bywx.getMiniProgramCode
The timing chart is as follows:
Process Dxplaination
- System login stateAutomatic maintenance of multi-terminal base library
- If the system login state does not exist, the
wx.getMiniProgramCodeWill evoke the WeChat Mini Program, after the user logs in successfully, return toMini Program Code。(Note: The multi-terminal base library will automatically generate and maintain the system login state. Effective within days) - If the system login state exists, the
wx.getMiniProgramCodeWill return immediately.Mini Program Code
- If the system login state does not exist, the
- App Login PageOfficial Offer Template (Weixin DevTools - Explorer - Select Folder and Right Click - New Multi-terminal Login Page), developers need to choose their own path into the code package, and in the
App.miniApp.jsonConfigure the following information in
// App.miniApp.json
{
"identityServiceConfig":
{
"authorizeMiniprogramType": 1, // You can specify the version of the jump Mini Program (0: official version, 1: development version, 2: experience version)
"miniprogramLoginPath": "/pages/donutLogin /donutLogin // Need to change the path selected by the business
}
}
- Mini Program authorization pageProvided by the official, developers need to be in the
App.jsonConfigure the following information in.
// App.json
{
"miniApp": {
"useAuthorizePage": true
}
}
Note: The official template provided by the App Login page only supports Mini Program call after successful login wx.getMiniProgramCode。
# Custom Login Page
Applicable scenarios: Developers have a custom Mini Program login page needs
Small code modification:
- Implement a custom Mini Program login page that is called when the user logs on
wx.weixinMiniProgramLogin - In the Mini Program code.
wx.loginReplaced bywx.getMiniProgramCode
The timing chart is as follows:
Process Dxplaination
- Pre-call wx.weixinMiniProgramLogin And logged in successfully. Within 30 days if the call wx.getMiniProgramCode Can be silently accessed
Mini Program Code
# II. Support for multiple login schemes
Application scenarios: Developers have a need to support multiple login methods
Small code modification:
- Implement a custom login page, provided by this product through theTypes of Login MethodsFor user login.
- In the Mini Program code.
wx.loginReplaced bywx.getIdentityCode
Background Service Code Modification:
- Received by the front end after a successful login Code (by
wx.getIdentityCodeorwx.xxxLoginreturn), Through code2Verifyinfo Get user identification information from WeChat. - Returns the Mini Program custom login state.
Timing Chart:
The program timing chart can be referred toMultiterminal application login timing。
Process Dxplaination
- Pre-call wx.xxxLogin And logged in successfully. Within 30 days if the call wx.getIdentityCode You can silently get the data that is used to code2Verifyinfo of
CodeTherefore, the developer can replace the full amount of thewx.loginforwx.getIdentityCodeTo and maintain the user experience of silently logging in.