# wx.weixinAppLogin

  • Mobile app WeChat login is a way to evoke the user's WeChat APP How to log in. call JSAPI Implement the login method and obtain a temporary login certificate (Code)Through credentials in exchange for user identification information.
  • In addition, after logging in successfully, you can call WeChat JSAPI To use WeChat open capabilities, such as cloud development.

Note: This interface is not supported inMobile App AssistantDebugging, developers need to build Apk or ipa Install to the phone before debugging

# Front preparation

  • [Multiple application accounts need to bind mobile application accounts](https://dev.weixin.qq.com/docs/framework/Guideline/web/bind-openapp .html)
  • Need to be in the project.miniapp.json Tick OpenSDK

# parameter

# Object object

attribute type Default value Required Introductions
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, and it's not a transfer app. 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
10001007 Multiterminal Apps Unbound Mobile Apps
10001015 Multiple Application Binding Mobile App 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.weixinAppLogin({
  success (res) {
    if (res.code) {
      // Initiate a network request
      wx.request({
        url: 'https://example.com/onLogin',
        data: {
          code: res.code
        }
      })
    } else {
      console.log('Login failed! ' + res.errMsg )
    }
  }
})

// Login After success, you can directly use the cloud development capabilities
wx.cloud.callFunction({
  name: 'myCloudFunction'
})