The API for login is wx.login(Object object).
Property | Type | Default value | Required | Description |
success | function | - | False | Callback function for successful API calls |
fail | function | - | False | Callback function for failed API calls |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure) |
Property | Type | Description |
code | string | User login credential (valid for five minutes). Developers need to call jscode2sessionin the server backend, and use the code to retrieve openid and session_key. |
Property | Type | Description |
errMsg | string | Error message. |
errno | Number |
wx.login({success (res) {if (res.code) {// Initiate a network requestwx.request({url: 'https://example.com/onLogin',data: {code: res.code}})} else {console.log('Login failed!' + res.errMsg)}}})
The API for checking session status is wx.checkSession(Object object).
Property | Type | Default value | Required | Description |
success | function | - | False | Callback function for successful API calls |
fail | function | - | False | Callback function for failed API calls |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure) |
wx.checkSession({success () {// The session_key has not expired and remains valid for this lifecycle.},fail () {// The session_key has expired, and the login process needs to be executed again.wx.login() // Log in again.}})
The API for getting account information is Object wx.getAccountInfoSync().
Property | Type | Description |
miniProgram | Object | Mini program account information |
Structural property | Type | Description |
appId | string | Mini program appId |
envVersion | string | Mini program version. Valid values: develop: The development version trial: The Preview release: The official version |
version | string | Online mini program version number |
The API for getting user profile is wx.getUserProfile(Object object).
Property | Type | Default value | Required | Description |
lang | string | en | False | The language used to display the user information. Valid values: en: English zh_CN: Simplified Chinese zh_TW: Traditional Chinese |
desc | string | - | True | Describes the purpose of retrieving user information. Up to 30 characters. |
success | function | - | False | Callback function for successful API calls |
fail | function | - | False | Callback function for failed API calls |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure) |
The API for getting user information is wx.getUserInfo(Object object).
Property | Type | Default value | Required | Description |
lang | string | en | False | The language used to display the user information. Valid values: en: English zh_CN: Simplified Chinese zh_TW: Traditional Chinese |
success | function | - | False | Callback function for successful API calls |
fail | function | - | False | Callback function for failed API calls |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure) |
Property | Type | Description |
userInfo | UserInfo | User information object |
<!-- If only displaying user avatar and nickname, the <open-data /> component can be used --><open-data type="userAvatarUrl"></open-data><open-data type="userNickName"></open-data><!-- The button must be used for login authorization --><button wx:if="{{canIUse}}" open-type="getUserInfo" bindgetuserinfo="bindGetUserInfo">Login authorization</button><view wx:else>Please upgrade the host client version.</view>
Page({data: {canIUse: wx.canIUse('button.open-type.getUserInfo')},onLoad: function() {// Check if the user has already authorized.wx.getSetting({success (res){if (res.authSetting['scope.userInfo']) {// Already authorized, can directly call getUserInfo to get user profile photo and nickname.wx.getUserInfo({success: function(res) {console.log(res.userInfo)}})}}})},bindGetUserInfo (e) {console.log(e.detail.userInfo)}})
// Must be called when the user has already authorized.wx.getUserInfo({success: function(res) {var userInfo = res.userInfovar nickName = userInfo.nickNamevar avatarUrl = userInfo.avatarUrl}})
Property | Type | Description |
nickName | string | User’s nickname. |
avatarUrl | string | The URL of the user's profile photo. The last number in the URL represents the size of the square profile photo (options are 0, 46, 64, 96, 132; 0 represents a 640x640 square profile photo, 46 represents a 46x46 square profile photo, and so on. The default value is 132.) This field is left blank if the user has no profile photo. If the user changes the profile photo, the original profile photo URL will become invalid. |
gender | number | User's gender. No longer returned. Valid values are: 0: Unknown 1: Male 2: Female |
country | string | The user’s country. No longer returned. |
province | string | The user's province. No longer returned. |
city | string | The user's city. No longer returned. |
language | string | The language used to display the country, province, and city. Valid values: en: English zh_CN: Simplified Chinese zh_TW: Traditional Chinese |
Property | Description |
boolean scope.userLocation | Whether to authorize location access, corresponding to the wx.getLocation and wx.chooseLocation |
boolean scope.writePhotosAlbum | Whether to authorize saving to the photo album, corresponding to the wx.saveImageToPhotosAlbum. |
boolean scope.camera | Whether to authorize camera access, corresponding to the <camera /> component. |
boolean scope.addFriend |
The API for settings is wx.getSetting(Object object).
Property | Type | Default value | Required | Description |
success | function | - | False | Callback function for successful API calls |
fail | function | - | False | Callback function for failed API calls |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure) |
Property | Type | Description |
authSetting | AuthSetting | User authorization result. |
wx.getSetting({success(res) {console.log(res.authSetting)// res.authSetting = {// "scope.userInfo": true,// "scope.userLocation": true// }}})
The API for opening settings page is wx.openSetting(Object object).
Property | Type | Default value | Required | Description |
success | function | - | False | Callback function for successful API calls |
fail | function | - | False | Callback function for failed API calls |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure) |
Property | Type | Description |
authSetting | AuthSetting | User authorization result. |
wx.openSetting({success(res) {console.log(res.authSetting)// res.authSetting = {// "scope.userInfo": true,// "scope.userLocation": true// }}})
wx.openSetting({success (res) {console.log(res.authSetting)// res.authSetting = {// "scope.userInfo": true,// "scope.userLocation": true// }}})
The API for checking biometric information is wx.checkIsSoterEnrolledInDevice(Object object).
Property | Type | Default value | Required | Description |
success | function | - | False | Callback function for successful API calls |
fail | function | - | False | Callback function for failed API calls |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure) |
Property | Type | Description |
isEnrolled | boolean | Whether the information has been entered. |
errMsg | string | Error message. |
wx.checkIsSoterEnrolledInDevice({success(res) {console.log(res.isEnrolled)}})
The API for checking biometric authentication support is wx.checkIsSupportSoterAuthentication(Object object).
Property | Type | Default value | Required | Description |
success | function | - | False | Callback function for successful API calls |
fail | function | - | False | Callback function for failed API calls |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure) |
wx.checkIsSupportSoterAuthentication({success() {// Support biometric authentication}})
The API for starting biometric authentication is wx.startSoterAuthentication(Object object).
Property | Type | Default value | Required | Description |
authContent | string | '' | False | Verification description, i.e. the prompts displayed during the authentication |
success | function | - | False | Callback function for successful API calls |
fail | function | - | False | Callback function for failed API calls |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure) |
wx.startSoterAuthentication({authContent: 'Unlock biometric authentication',success() {// Authentication successful}})
The API for authorization is wx.authorize(Object object).
Property | Type | Default value | Required | Description |
scope | string | - | True | |
success | function | - | False | Callback function for successful API calls |
fail | function | - | False | Callback function for failed API calls |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure) |
// You can query whether the user has authorized the scope of "scope.record" using wx.getSettingwx.getSetting({success(res) {if (!res.authSetting['scope.record']) {wx.authorize({scope: 'scope.record',success() {// Once the user has granted permission for the mini program to use the recording feature, subsequent calls to the wx.startRecord API will not prompt the user for permission again.wx.startRecord()}})}}})
The API for subscription is wx.requestSubscribeMessage(Object object).
Property | Type | Default value | Required | Description |
tmplIds | Array | - | True | Array of message template IDs to subscribe to. A maximum of 3 messages can be subscribed to in one call. Template IDs are configured in the console under Mini program management - Subscription. Each tmplId must correspond to a unique template title, otherwise duplicates will be filtered out. |
success | function | - | False | Callback function for successful API calls |
fail | function | - | False | Callback function for failed API calls |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure) |
Property | Type | Description |
errMsg | String | The value of errMsg is 'requestSubscribeMessage:ok' when the API is called successfully. |
[TEMPLATE_ID: string] | String | TEMPLATE_ID indicates the template ID, which is a dynamic key. Valid values: accept, reject, ban, filter. [TEMPLATE_ID] is a dynamic key representing the template ID. The value can be 'accept', 'reject', 'ban', or 'filter'. Accept: The user agreed to subscribe to the message corresponding to this template ID. Reject: The user refused to subscribe to the message corresponding to this template ID. Ban: The template has been banned by the backend. Filter: The template was filtered out by the backend due to duplicate titles. For example, { errMsg: "requestSubscribeMessage:ok", zun-LzcQyW-edafCVvzPkK4de2Rllr1fFpw2A_x0oXE: "accept"} indicates that the user has agreed to subscribe to the message zun-LzcQyW-edafCVvzPkK4de2Rllr1fFpw2A_x0oXE. |
Property | Type | Description |
errMsg | string | Error message when the API call fails. |
errno | Number | Error code when the API call fails. |
errCode | errMsg | Description |
10001 | TmplIds can't be empty. | The tmplIds parameter is empty. |
10002 | Failed to request the message list. | Network error. Failed to request the message list. |
10003 | Failed to send the subscription request. | Network error. Failed to send the subscription request. |
20001 | No template data return, verify if the template ID exists. | No template data, usually because the template ID does not exist or does not match the template type. |
20002 | Templates type must be the same. | Both one-time and permanent template IDs are used. |
20003 | There are too many template messages. | The number of template messages exceeds the limit. |
20004 | The main switch is switched off. | Subscriptions cannot be made because the user has switched off the main switch. |
20005 | This mini program is banned from subscribing messages. | The mini program is banned from subscribing messages. |
20013 | Reject DeviceMsg Template | Subscription to device messages using this API is not allowed. |
wx.requestSubscribeMessage({tmplIds: [''],success: (res) => {console.log('requestSubscribeMessage===success', res)}})
Was this page helpful?