# wx.login(Object object)

with Promise style call: Not supported

Mini Program plugin: Support, need to Mini Program base library version no less than 2.3.1

When used in Mini Programs plug-ins, it needs to be called after obtaining user authorization in the user information feature page. Otherwise, return fail。 See for details User Information Function Page

WeChat Windows edition:: Support

WeChat Mac edition:: Support

Call the interface to get the login credentials code. Through the certificate and exchange user login state information, including the user in the current Mini Program unique identity (openid), WeChat open platform account under the unique identifier (uniid, If the current Mini Program has been bound to the WeChat open platform account and the session key (session)_Key) and so on. User data encryption and decryption communication needs to rely on the session key to complete. For more usage see Mini Program login

# parameter

# Object object

attribute type Default values Required Introductions Minimum version
timeout number no Timeout, in ms 1.9.90
success function no Interface calls the successful callback function
fail function no Interface calls failed callback functions
complete function no Interface calls the end of the callback function (call success or failure will be executed)

# object.success callback

# parameter
# Object res
attribute type Introductions
code string User login credentials (valid for 5 minutes). The developer needs to invoke the auth.code2Session, using code Exchange for openid、unionid、session_key Wait information

# sample code

wx.login({
  success (res) {
    if (res.code) {
      //Initiate Network Request
      wx.request({
        url: 'https://example.com/onLogin',
        data: {
          code: res.code
        }
      })
    } else {
      console.log('Login failed! ' + res.errMsg)
    }
  }
})