wx.weixinAppLogin

View Markdown

Last edited on 2026-07-14

  • Mobile app WeChat Login is a method that invokes the user's WeChat APP to perform login. Call the JSAPI to implement this login method and obtain a temporary login credential (code). Use the credential to exchange for user identity information and so on.
  • Additionally, after successful login, you can call WeChat JSAPI to use WeChat open capabilities, such as Cloud Development.

Note: This API does not support debugging in the "Mobile App Assistant." Developers must build an apk or ipa and install it on a phone before debugging.

Prerequisites

Parameters

Object object

Attribute Type Default Value Required Description
success function No Callback function executed when the API call succeeds
fail function No Callback function executed when the API call fails
complete function No Callback function executed when the API call ends

object.success callback function

Parameters
Object res
Attribute Type Description
code string User login credential (valid for five minutes). Developers can call code2Verifyinfo on the developer server to exchange the code for user identification information, etc.
Note that code2Verifyinfo uses the appid and secret of the multi-end application, not the appid and secret of Mini Program, nor the appid and secret of the mobile application

object.fail Callback Function

Parameters
Object res
Attribute Type Description
errCode number Error code
errMsg string Error message

res.errCode

errCode Description
-1 System error
10001005 Mini Program has not integrated identity management
10001007 Mini Program has not bound a mobile app
10001015 Error binding Mini Program to a mobile app (If testing this interface in the Mobile App Assistant, this error will occur)
-700000 Front-end error, errMsg will provide detailed information

Common Front-end Errors

errMsg Guidance
sendOpenReq:fail launch wechat fail Failed to launch WeChat, which means your Mini Program has not bound a mobile app account, causing the OpenSDK to fail. Solution: Bind Mobile App Account

Sample Code

wx.weixinAppLogin({
  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)
    }
  }
})

// After successful login, you can directly use Cloud Development features
wx.cloud.callFunction({
  name: 'myCloudFunction'
})