Jumps to WeChat to obtain the WeChat login state.
Notes:
-
This API requires applying for and initializing the WeChat Open capability. The client must perform the relevant configuration.
-
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.
-
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 thecodevia this API, you can call the /sns/oauth2/access_token API to obtain anaccess_token, and use the /sns/userinfo API to retrieve user information. - Note: The
appidandsecretused to generate theaccess_tokenmust 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)
}
})