wx.miniapp.login

View Markdown

Last edited on 2026-08-21

Jumps to WeChat to obtain the WeChat login state.

Notes:

  1. This API requires applying for and initializing the WeChat Open capability. The client must perform the relevant configuration.

  2. This API does not support debugging in the "Mobile Application Assistant". Developers must build an APK or IPA and install it on a mobile device to enable debugging.

  3. This API is now supported on the HarmonyOS platform.

Pre-integration Notes

  • This feature depends on the WeChat Open SDK. You must follow the guidelines to create a Mobile Application account on the WeChat Open Platform to complete the necessary initialization configurations. For details, see the WeChat Mobile Application Capability Initialization Guide.
  • The underlying scope for this API is snsapi_userinfo. After obtaining the code via this API, you can call the /sns/oauth2/access_token API to obtain an access_token, and use the /sns/userinfo API to retrieve user information.
  • Note: The appid and secret used to generate the access_token must be those of the Mobile Application account on the WeChat Open Platform.

Parameters

Attribute Type Default Value Required Description
success function Yes Success callback after retrieval

JSAPI Code Example

// login
wx.miniapp.login({
    success: (res) => {
        console.log('login success:', res.code)
    }
})