tencent cloud

All product documents
Tencent Cloud Super App as a Service
Open APIs
Last updated: 2025-03-20 18:01:57
Open APIs
Last updated: 2025-03-20 18:01:57

Login

login

The API for login is wx.login(Object object).
Feature description: This API is used to obtain a login credential. The credential can then be used to retrieve user login status information.
Notes:
The v2 version (Only supported on SaaS) can refer to the Practical Tutorial for guidance. It can be directly invoked in the IDE (minimum supported version: 2.1.111).
The v1 version requires coordination with the host client. The content returned on the actual device is provided by the host client. The host's return values can be customized. In the IDE, you can use the mock panel to mock the return values.
For version control rules, please refer to the apiVersion configuration.
Parameter and description: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)
object.success callback function parameter:Object res
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.
object.fail callback function parameter:Object err
Property
Type
Description
errMsg
string
Error message.
errno
Number
An error code. For details of error codes, see Error Codes.
Example:
wx.login({
success (res) {
if (res.code) {
// Initiate a network request
wx.request({
url: 'https://example.com/onLogin',
data: {
code: res.code
}
})
} else {
console.log('Login failed!' + res.errMsg)
}
}
})

checkSession

The API for checking session status is wx.checkSession(Object object).
Feature description: This API checks whether the login session has expired.
Notes:
1. The v2 version (Only supported on SaaS) can refer to the practice documentation for guidance. It can be directly invoked in the IDE (minimum supported version: 2.1.111).
The session_key is unique. At any given time, a user can have only one valid session_key while using the mini program.
The user login status obtained through the wx.login has a certain validity period. Developers can call the wx.checkSession to check if the current user login status is still valid.
wx.checkSession checks the session_key corresponding to the last code obtained. A successful call indicates that the session_key has not expired, while a failed call indicates that the session_key has expired.
If the login status has expired, developers can call wx.login again to obtain a new user login status.
2. The v1 version requires coordination with the host client. The content returned on the actual device is provided by the host client. The host's return values can be customized. In the IDE, you can use the mock panel to mock the return values.
3. For version control rules, please refer to the apiVersion configuration.
Parameter and description: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)
Example:
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.
}
})

Account information

Notes:
APIs related to account information are supported in mini programs but not in mini games.

getAccountInfoSync

The API for getting account information is Object wx.getAccountInfoSync().
Feature description:This API retrieves current account information. The online mini program version number can only be obtained in the official version, not the development or trial versions.
Return value:Object, account information.
Property
Type
Description
miniProgram
Object
Mini program account information
miniProgram structure parameters
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

User information

Notes:
APIs related to account information are supported in mini programs but not in mini games.

getUserProfile

The API for getting user profile is wx.getUserProfile(Object object).
Feature description: This API is currently not supported in IDE and needs to be jointly tested with the host client. The content return value on the device is provided by the host client, and can be customized.
In the IDE, you can mock the return value on the mock panel.
Retrieves the user information. It can only be called after a page click event (for example, in the callback of bindtap on a button). An authorization popup window will appear for each request, and userInfo will be returned upon user consent. This API replaces wx.getUserInfo.
Return value: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)

getUserInfo

The API for getting user information is wx.getUserInfo(Object object).
Feature description: This API is currently not supported in IDE and needs to be jointly tested with the host client. The content return value on the device is provided by the host client, and can be customized.
In the IDE, you can mock the return value on the mock panel.
To retrieve the user information, the user authorization for scope.userInfo. is required.
Parameter and description: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)
Callback function parameter of object.success: Object res
Property
Type
Description
userInfo
UserInfo
User information object
Example
Example for the mini program user information component (user authorization)
<!-- 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)
}
})
Example:
// Must be called when the user has already authorized.
wx.getUserInfo({
success: function(res) {
var userInfo = res.userInfo
var nickName = userInfo.nickName
var avatarUrl = userInfo.avatarUrl
}
})

userInfo

Feature description:User information.
Parameter and description:
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

Settings

AuthSetting

Feature description:User’s authorization settings information.
Parameter and description:
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
Allows to be added as friends. Call wx.authorize for authorization.

getSetting

The API for settings is wx.getSetting(Object object).
Feature description:Gets the current settings of the user.
Parameter and description: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)
object.success callback function parameter:Object res.
Property
Type
Description
authSetting
AuthSetting
User authorization result.
Example:
wx.getSetting({
success(res) {
console.log(res.authSetting)
// res.authSetting = {
// "scope.userInfo": true,
// "scope.userLocation": true
// }
}
})

openSetting

The API for opening settings page is wx.openSetting(Object object).
Feature description:This API opens the mini program settings page in the client, returning the user's settings operation results. After the user taps, they can navigate to the settings page to manage authorization information.
Parameter and description: 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)
object.success callback function parameter:Object res.
Property
Type
Description
authSetting
AuthSetting
User authorization result.
Example:
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
// }
}
})

Biometric authentication

Notes:
APIs related to biometric authentication are supported in mini programs but not in mini games.

checkIsSoterEnrolledInDevice

The API for checking biometric information is wx.checkIsSoterEnrolledInDevice(Object object).
Feature description:This API checks whether biometric information is entered into the device.
Parameter and description: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)
object.success callback function parameter:Object res.
Property
Type
Description
isEnrolled
boolean
Whether the information has been entered.
errMsg
string
Error message.
Example:
wx.checkIsSoterEnrolledInDevice({
success(res) {
console.log(res.isEnrolled)
}
})

checkIsSupportSoterAuthentication

The API for checking biometric authentication support is wx.checkIsSupportSoterAuthentication(Object object).
Feature description:This API checks whether the current device supports biometric authentication. If supported, the success callback is triggered; if not supported, the fail callback is triggered.
Parameter and description: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)
Example:
wx.checkIsSupportSoterAuthentication({
success() {
// Support biometric authentication
}
})

startSoterAuthentication

The API for starting biometric authentication is wx.startSoterAuthentication(Object object).
Feature description:This API starts the biometric authentication.
Parameter and description: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)
Example:
wx.startSoterAuthentication({
authContent: 'Unlock biometric authentication',
success() {
// Authentication successful
}
})

Authorization

authorize

The API for authorization is wx.authorize(Object object).
Feature description:This API initiates an authorization request to the user in advance. After this API is called, a window will pop up, asking the user whether they agree to authorize the mini program to use a certain feature or access certain user data. However, the corresponding APIs are not actually called. If the user has previously agreed to the authorization, no pop-up window will appear and it will return success directly.
Parameter and description:Object object.
Property
Type
Default value
‍Required
Description
scope
string
-
True
Scope of the required permissions. For more information, see Scope list.
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)
Example:
// You can query whether the user has authorized the scope of "scope.record" using wx.getSetting
wx.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()
}
})
}
}
})

Subscription

requestSubscribeMessage

The API for subscription is wx.requestSubscribeMessage(Object object).
Feature description:This API triggers the client mini program's subscription message page and returns the user's subscription message operation result. You can learn the user’s subscription status for related template messages using wx.getSetting .
Notes:
Only supported on SaaS.
One-time template IDs and permanent template IDs cannot be used simultaneously.
In a single authorization call, each tmplId must correspond to a unique template title. If there are duplicates, only one will be retained.
Parameter and description: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)
object.success callback function parameter:Object res
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.
object.fail callback function parameter:Object err
Property
Type
Description
errMsg
string
Error message when the API call fails.
errno
Number
Error code when the API call fails.
Error code
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.
Example:
wx.requestSubscribeMessage({
tmplIds: [''],
success: (res) => {
console.log('requestSubscribeMessage===success', res)
}
})


Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

7x24 Phone Support
Hong Kong, China
+852 800 906 020 (Toll Free)
United States
+1 844 606 0804 (Toll Free)
United Kingdom
+44 808 196 4551 (Toll Free)
Canada
+1 888 605 7930 (Toll Free)
Australia
+61 1300 986 386 (Toll Free)
EdgeOne hotline
+852 300 80699
More local hotlines coming soon