# WeChat login instructions
In a multiterminal application, developers can use the following 3 individual api To achieve WeChat login:
Interface name | Function introduction | Other Notes |
---|---|---|
wx.login | - The interface is used in the App Jump to the Mini Program to log in, log in and then return App - The interface returns the jscode , available through the Mini Program jscode2session Interface to get the user's Openid as well as Unionid (if the Mini Program is bound to WeChat open platform account) - This interface is only available for the development version, not as a full version solution | - Need to register WeChat open platform mobile application account - Can be tested in Mobile App Assistant |
wx.miniapp.login | - This interface is[Mobile App WeChat Login](https://developers.weixin.qq.com/doc/oplatform/Mobile_App/WeChat_Log in/Development_Guide.html)Function encapsulation, users go to WeChat App Code can be obtained after authorization - The interface returns the Code , available through the mobile application of the[/Sns/oauth2/access_Token](https://developers.weixin.qq.com/doc/oplatform/Mobile_App/WeChat_Log in/Development_Guide.html) Interface to get the user's App to hit the target Openid as well as unionID - adopt unionID Can be used by users in App The identity of the Mini Program is associated with the identity on | - Need to register WeChat open platform mobile application account - You cannot test in Mobile App Assistant, please build the installation package to test on the real machine |
wx.weixinAppLogin | - The interface is based on the[Mobile App WeChat Login](https://developers.weixin.qq.com/doc/oplatform/Mobile_App/WeChat_Log in/Development_Guide.html)Functional combinationMultiterminal identity managementEncapsulated, users go to WeChat App After authorization to obtain Code - The interface returns the Code , which can be managed through a multiterminal identitycode2Verifyinfo Interface to get the user's App to hit the target Openid - WeChat login based on the interface, can use the ability of cloud development in multi-terminal applications | - Need to register WeChat open platform mobile application account - Multiple identity management capabilities required - You cannot test in Mobile App Assistant, please build the installation package to test on the real machine |
# I. Registration of Mobile Application Account
- 3 Each interface requires the developer to register the WeChat open platform mobile application account, if you already have a mobile application account, you can skip this step.If you do not have a mobile app account, you can follow the steps in this section to complete the creation and review.
# 1. Register WeChat Open Platform Account
- Go toWeChat Open PlatformComplete registration, detailed operating instructions can be viewedWeChat Open Platform Registration Guidelines
# 2. Create a mobile application account
- log inWeChat Open Platform, and head to theManagement Center - Mobile Applications
- to hitCreating Mobile Apps, and then fill in the mobile application name, introduction, official website, icon and other basic information and development information, and then submit to review
- After waiting for approval, you canManagement Center - Mobile Applications - Application DetailsTo view the mobile app in AppID information (Required when calling the interface)
# II. wx.miniapagelogin
# 1. Instructions for use
- wx.miniapp.login Be based on OpenSDK, associated with WeChat open platform transfer application The AppID, and the last thing you get is the user in the App to hit the target Openid
- If you need to associate the Mini Program's Openid Information, the Mini Program can be bound in the WeChat open platform, so as to obtain UnionID, via unionID Associate mobile apps with Mini Programs.
- Go to ViewInterface details
# 2. Initialization Configuration
Before using WeChat open capabilities, you need to complete the initialization configuration.
# 3. Call Example
Example:
// Login
wx.miniapp.login ({
success: (res) => {
console.log('login success:', res.code)
}
})
# III. wx.login
# 1. Instructions for use
- This interface is only suitable for the early rapid debugging phase and is not intended as a App The formal scheme for logging in, it is recommended to use the wx.miniapp.login or [wx.getMiniProgramCode ](https://dev.weixin.qq.com/docs/auth/jsapi/Weixin/wx.getMiniProgramCode .html)
- During the development debugging phase, which can be found in theMobile App AssistantExperience test in wx.loginScenarios where developers build packages are installed on the phone for debugging are not supported.
# 2. Steps to Use
When using the "upgrade to multi-terminal project" ability in the WeChat developer tool, the tool will automatically generate app.miniapp.json This file and fill in the corresponding information of the WeChat mini program you want to jump to.
app.miniapp.json File in Mini Program Project miniprogramRoot Directory configuration, the content has been automatically configured, developers do not need to adjust :
{
"adapteByMiniprogram": {
"userName": "xxxx", // Mini Program primitive id (not Mini Program appid)// And the field will be filled in by default, developers do not need to adjust
}
}
- In addition, when a multiterminal application is calling the wx.login Interface, where the base library has been implemented with compatible logic, so that developers do not have to perceive changes. Jump to the specific page of the target WeChat Mini Program, which will be executed inside the specific page, and execute the wx.login Interface, and finally pass the returned code content back to the multiterminal Mini Program. Finally, in the multi-terminal Mini Program wx.login of success Interface to return the WeChat Mini Program returned code。 So that developers continue to call the original way Wx.login without changing the business logic.
# IV. wx.weixinAppLogin
- Details can be viewedhttps://dev.weixin.qq.com/docs/auth/jsapi/Weixin/wx.weixinAppLogin.html