# wx.weixinMiniProgramLogin
- call wx.weixinMiniProgramLogin Can evoke WeChat mini program login, access to temporary login credentials (Code)In exchange for user identification information.
- In addition, after logging in successfully, you can call WeChat JSAPI (e.g.
wx.getMiniProgramCode
) Open ability to use WeChat(Cloud development, etc.
# Front preparation
- [Multiple application accounts need to bind mobile application accounts](https://dev.weixin.qq.com/docs/framework/Guideline/web/bind-openapp .html)
- Need more project.miniapp.json Tick OpenSDK
- Configure the evocative WeChat mini program version.
- in
app.miniapp.json
In, add “authorizeMiniprogramType” Parameter, you can specify the jump Mini Program version (0: Official, 1: Development, 2: Experience)。
- in
- Configuration Mini Program Official License Page
- in
app.json
In, add “useAuthorizePage” Parameter, and set to “true”。 Once configured, the Mini Program inserts the official Mini Program license page at compile time (The official license page does not occupy the code package volume)。
- in
- In the WeChat Developer Tool, select "Mini Program Mode," click Preview, and use WeChat to scan the code.
# parameter
# Object object
attribute | type | Default value | Required | Introductions |
---|---|---|---|---|
redirectPath | string | no | Specifies the page to which the authorized Mini Program is redirected | |
success | function | no | Interface calls a successful callback function | |
fail | function | no | Interface to call a failed callback function | |
complete | function | no | The callback function at the end of an interface call |
# object.success callback
# parameter
# Object res
attribute | type | Introductions |
---|---|---|
Code | string | User login credentials (valid for five minutes). The developer can call the code2Verifyinfo, Use Code In exchange for user identification information Be careful code2Verifyinfo It's a multi-application. appid And secret, not the Mini Program's. appid and secret |
# object.fail callback
# parameter
# Object res
attribute | type | Introductions |
---|---|---|
errCode | number | Error code |
errMsg | string | Error message |
**res.errCode **
errCode | Introductions |
---|---|
-1 | system error |
10001005 | Multiterminal Application Unplugged Identity Management |
10001008 | Multiterminal application unbound development Mini Program |
10001016 | Multiterminal application module binding development Mini Program error |
-700000 | Front End Error, errMsg Will give detailed hints |
Common Front End Errors
errMsg | guide |
---|---|
sendOpenReq:fail launch wechat fail | Pull up WeChat failed, that is, your multi-terminal application has not yet bound to the mobile application account, resulting in OpenSDK failed. Solutions:[Binding Mobile App Account](https://dev.weixin.qq.com/docs/framework/Guideline/web/bind-openapp .html) |
# sample code
wx.weixinMiniProgramLogin ({
redirectPath: 'pages/Home/index',
success (res) {
if (res.code) {
// Initiate a network request
wx.request({
url: 'https://example.com/onLogin',
data: {
code: res.code
}
})
// Login After success, you can directly use the cloud development capabilities
wx.cloud.callFunction({
name: 'myCloudFunction'
})
} else {
console.log('Login failed! ' + res.errMsg )
}
}
})