# Mini Program login service configuration

To make it easier for developers to accessMini Program login serviceServices, developer tools support one-click accessMultiterminal Identity Management ServicesThe required configuration is as follows.

# I. Configuration Instructions for Mini Program Login Services

# 1.1 app.miniapp.json

identityServiceConfig type describe Introductions
authorizeMiniprogramType 0 | 1 | 2 Used to specify wx.weixinMiniProgramLogin Jump Mini Program version 0: Official, 1: Development, 2: Experience
miniprogramLoginPath String Control call wx.getMiniProgramCode If the system login state fails, the login page will appear by default __default__ Only supports debugging in the real machine environment, debugging can be created on the tool.Multi-terminal login Page
adaptWxLogin Boolean Specifies the true The developer does not need to modify the project code to automatically wx.login The logic adapts to wx.getMiniProgramCode

# 1.2 app.json

MiniApp type describe Introductions
useAuthorizePage Boolean Used for wx.weixinMiniProgramLogin Insert in the Mini ProgramSmall Program Authorization Page

# 2.1 wx.weixinMiniProgramLogin

  • This interface needs[Add Mini Program Authorization Page](#Add Mini Programs authorization-page)

# 2.2 wx.getMiniProgramCode

  • This interface needs[Add Mini Program Authorization Page](#Add Mini Programs authorization-page)
  • as well as[Add Multiterminal Login Page](#Add multiterminal login - page)

# 2.3 Rapid adaptation wx.login

  • need[Add Mini Program Authorization Page](#Add Mini Programs authorization-page)
  • as well as[Add Multiterminal Login Page](#Add multiterminal login - page)
  • And needs[will wx.login Adapted to wx.getMiniProgramCode ](#Adapt -wxlogin - to -wXgetminiprogramcode )

# III. Configuration Operations

# Add Mini Program Authorization Page

The Multiterminal Identity Management Service supports the use ofMulti-terminal login, its flow for the user to click multi-terminal login, will jump to the multi-terminal application module bound by the Mini Program, after obtaining the Mini Program authorization can return to the multi-terminal application, and the developer can obtain the Mini Program jscode Information. Therefore, the following configuration is required:

  1. Insert in the Mini ProgramSmall Program Authorization Page, The Page The addition logic of the app.json to hit the target useAuthorizePage Control, namely:
// app.json
{
    "miniApp":  {
        "useAuthorizePage": true // true Indicates that it will authorize Page Inserted into the Mini Programfalse Indicates that it will not authorize Page Inserted into the Mini Program
    }
}
  1. In addition, it is necessary to app.miniapp.json In Configuration identityServiceConfig Information. authorizeMiniprogramType Controls the version of the Mini Program to be invoked at login (Note: When testing, it is recommended to configure 1, after the Mini Program is officially online, it is configured to 0)。 Namely:
// 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)
    }
}

# Add Multiterminal Login Page

Multi-terminal login PageControl call wx.getMiniProgramCode If the system login state fails, the login page will appear by default.

  • By default, to allow developers to quickly start debugging, developers can add miniprogramLoginPath Configured to __default__In constructing the App When you insert a default Multi-terminal login PageUsed to complete the wx.getMiniProgramCode The invocation of

Note: __default__ Only supports debugging in the real machine environment, debugging can be created on the tool.Multi-terminal login Page

// app.miniapp.json 
{
    "identityServiceConfig":  {
        "miniprogramLoginPath":  "__default__"  // This field will control the call to the wx.getMiniProgramCode  If the login state fails, the login page will appear by default
    }
}

Default Multi-terminal login Page:

  • To further reduce the cost of developing multi-terminal application login pages, Developer Tools also provides a template for multi-terminal login pages, which developers can customize based on the template. Specific operations:Weixin DevTools-> Resource Manager -> Select the folder and right click-> New multi-terminal login Page

# will wx.login Adapted to wx.getMiniProgramCode

  • Developers themselves. wx.login Replaced by Wx.getminiprogramcode, but considering that this code needs to be also the code of the Mini Program, and in the Mini Program still needs to call Wx.login, developers need to use conditional compiled syntax for compatibility

  • To further reduce the developer's handling of compatible logic here, apageminiapagejson newly added adaptWxLogin Parameter is used to control whether in multiterminal application mode the wx.login Adapted to wx.getMiniProgramCode。 Namely:

// app.miniapp.json 
{
    "identityServiceConfig":  {
        "adaptWxLogin": true 
    }
}

# IV. One-Click Configuration Mini Program Login Service

Developers can follow the above guidelines step by step configuration, or with the help of developer-providedMini Program login service configurationFunction one-click to complete the relevant configuration.

# 4.1 Download the WeChat Developer Tool

# 4.2 Enter Multiterminal Application Mode and Configure Mini Program Login Service

  • Upgrade the original Mini Program project to multi-terminal project, and switch to multi-terminal application mode
  • Go tomenu bar - tool - Configure Mini Program login service
  • to hitdetermineYou can complete the Mini Program login service configuration with one click
  • Just a moment to configure successfully

# 4.3 Special Considerations

  • The relevant configuration developer tools have helped developers do this, but to be effective, developers will not only need to rebuild in multi-app mode. App, also need to cut back to Mini Program mode, and then rebuild the Mini Program new version will take effect!!!
  • In the default configuration, the Mini Program login configured for the developer is the jumpDevelopment versionMini Program to log in, so the developer needs to cut back to Mini Program mode and then re-preview, then scan the QR code using WeChat to make sure you already have the latest version on your phone.Mini Program authorization pageofDevelopment Mini Program