tencent cloud

Feedback

Open APIs

Last updated: 2024-11-21 18:41:53

    Login

    login

    This method is used via wx.login(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 follow the WeChat standard or be customized.In the IDE, you can mock the return value on the mock panel.
    Parameter and Description: Object.
    Attribute
    Type
    Default value
    Required
    Description
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Sample Code
    wx.login({
    success(res) {
    console.log(res ,"---------------info, host app return");
    }
    })

    checkSession

    This API is used via wx.checkSession(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 follow the WeChat standard or be customized.
    In the IDE, you can mock the return value on the mock panel.
    Checks if the login session has expired. The login session obtained through the wx.login API has a certain validity period. The longer the user does not use the mini program, the more likely the login session will expire. On the contrary, if the user continuously uses the mini program, the login session remains valid. The specific validity logic is maintained by TCMPP and is open to developers. Developers only need to call the wx.checkSession API to check whether the current login is valid.
    If the login session expires, the developer can call wx.login again to obtain a new login session. A successful call indicates that the current session\\_key has not expired, while a failed call indicates that the session\\_key has expired.
    Parameter and Description: Object.
    Attribute
    Type
    Default value
    Required
    Description
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Sample Code
    wx.checkSession({
    success() {
    // The session_key has not expired and remains valid throughout its lifecycle.
    },
    fail () {
    // The session_key has become invalid and the login process needs to be executed again.
    wx.login() // Log in again.
    }
    })

    Account information

    getAccountInfoSync

    This API is used via Object wx.getAccountInfoSync().
    Feature Description: Obtains 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.
    Attribute
    Type
    Description
    miniProgram
    Object
    Mini program account information.
    miniProgram Structure Attributes
    Structure attributes
    Type
    Description
    appId
    string
    Mini program appId
    envVersion
    string
    Mini program version, whose valid values are:
    develop: Development Version
    trial: Trial Version
    release: Official Version
    version
    string
    Online Mini Program Version Number

    User information

    getUserProfile

    This API is used via 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 follow the WeChat standard or be customized.
    In the IDE, you can mock the return value on the mock panel.
    Obtains 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.For more details, see Descriptions of User Information Interface Adjustment.
    Return Value: Object.
    Attribute
    Type
    Default value
    Required
    Description
    lang
    string
    en
    No
    The language for displaying user information, whose valid values are:
    en: English
    zh_CN: Simplified Chinese
    zh_TW: Traditional Chinese
    desc
    string
    -
    Yes
    Declare the purpose of obtaining user personal information, not exceeding 30 characters.
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)

    getUserInfo

    This API is used via 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 follow the WeChat standardor be customized.
    In the IDE, you can mock the return value on the mock panel.
    To obtain the user information, the user authorization for scope.userInfo. is required.
    Parameter and Description: Object.
    Attribute
    Type
    Default value
    Required
    Description
    lang
    string
    en
    No
    The language for displaying user information, whose valid values are:
    en: English
    zh_CN: Simplified Chinese
    zh_TW: Traditional Chinese
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Parameters for object.success callback function: Object res
    Attribute
    Type
    Description
    userInfo
    UserInfo
    User information object
    Example code for the mini program user's information component
    <!-- 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 authorization is granted.
    wx.getSetting({
    success(res) {
    if (res.authSetting['scope.userInfo']) {
    // Authorization has been granted and getUserInfo can be directly invoked to get avatar and nickname.
    wx.getUserInfo({
    success: function(res) {
    console.log(res.userInfo)
    }
    })
    }
    }
    })
    },
    bindGetUserInfo (e) {
    console.log(e.detail.userInfo)
    }
    })
    Sample Code
    // Must be invoked under the condition that the user has already granted authorization.
    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:
    Attribute
    Type
    Description
    nickName
    string
    User Nickname
    avatarUrl
    string
    The URL of the user's avatar image. The last digit in the URL represents the size of the square avatar (options include 0, 46, 64, 96, 132; 0 represents a 640x640 square avatar, 46 represents a 46x46 square avatar, and the remaining values follow this pattern. The default selection is 132). This field is empty if the user does not have an avatar. If the user changes their avatar, the original avatar URL will become invalid.
    gender
    number
    User gender, no longer returned. Valid values are:
    0: Unknown
    1: Male
    2: Female
    country
    string
    The country where the user is located. No longer returned.
    province
    string
    The province where the user is located. No longer returned.
    city
    string
    The city where the user is located. No longer returned.
    language
    string
    The language used to display country, province, city. "zh_CN" is forcibly returned. Valid values are:
    en: English
    zh_CN: Simplified Chinese
    zh_TW: Traditional Chinese

    Settings

    AuthSetting

    Feature Description: User authorization settings information.
    Parameter and Description:
    Attribute
    Description
    boolean scope.userLocation
    Whether to authorize geographical location, corresponding to the interface wx.getLocation Whether to authorize geographical location, corresponding to the interface wx.chooseLocation
    boolean scope.writePhotosAlbum
    Whether to authorize saving to the album wx.saveImageToPhotosAlbum
    boolean scope.camera
    Whether to authorize the camera, corresponding to the <camera /> component.
    boolean scope.addFriend
    Allow to be added as a friend, proactively call the wx.authorize interface for authorization.

    getSetting

    This API is used via wx.getSetting(Object object).
    Feature Description: Gets the current settings of the user.
    Parameter and Description: Object.
    Attribute
    Type
    Default value
    Required
    Description
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Parameters for object.success callback function: Object res.
    Attribute
    Type
    Description
    authSetting
    AuthSetting
    User Authorization Results
    Sample Code
    wx.getSetting({
    success(res) {
    console.log(res.authSetting)
    // res.authSetting = {
    // "scope.userInfo": true,
    // "scope.userLocation": true
    // }
    }
    })

    openSetting

    This API is used via wx.openSetting(Object object).
    Feature Description: Invokes the client’s mini program settings interface and returns the user's operation result. When the user click the button, they will be redirected to the settings page to manage their authorization.
    Parameter and Description: Object.
    Attribute
    Type
    Default value
    Required
    Description
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Parameters for object.success callback function: Object res.
    Attribute
    Type
    Description
    authSetting
    AuthSetting
    User Authorization Results
    Sample Code
    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

    checkIsSoterEnrolledInDevice

    This API is used via wx.checkIsSoterEnrolledInDevice(Object object).
    Feature Description: Verifies whether the biometric information is entered into the device.
    Parameter and Description: Object.
    Attribute
    Type
    Default value
    Required
    Description
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Parameters for object.success callback function: Object res.
    Attribute
    Type
    Description
    isEnrolled
    boolean
    Whether information has been entered.
    errMsg
    string
    Error Message
    Sample Code
    wx.checkIsSoterEnrolledInDevice({
    success(res) {
    console.log(res.isEnrolled)
    }
    })

    checkIsSupportSoterAuthentication

    This method is used via wx.checkIsSupportSoterAuthentication(Object object).
    Feature Description: Checks whether the device supports biometric authentication. If yes, “success” is called, otherwise “fail” is called.
    Parameter and Description: Object.
    Attribute
    Type
    Default value
    Required
    Description
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Sample Code
    wx.checkIsSupportSoterAuthentication({
    success() {
    // Supports biometric authentication.
    }
    })

    startSoterAuthentication

    This method is used via wx.startSoterAuthentication(Object object).
    Feature Description: Starts the biometric authentication.
    Parameter and Description: Object.
    Attribute
    Type
    Default value
    Required
    Description
    authContent
    string
    ''
    No
    This is the verification description, meaning the dialog box prompt content will be displayed on the interface during the identification process.
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Sample Code
    wx.startSoterAuthentication({
    authContent: 'Unlock via Biometric Authentication',
    success() {
    // Authentication successful
    }
    })

    Authorization

    Authorization

    This API is used via wx.authorize(Object object).
    Feature Description: * 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.
    Attribute
    Type
    Default value
    Required
    Description
    scope
    string
    -
    Yes
    Scope of permissions required,See scope for details
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Sample Code
    // You can first query whether the user has authorized the "scope.record" scope using wx.getSetting.
    wx.getSetting({
    success(res) {
    if (!res.authSetting['scope.record']) {
    wx.authorize({
    scope: 'scope.record',
    success() {
    
    // The user has already agreed to the mini program's use of the recording function, so subsequent calls to the wx.startRecord interface will not prompt a pop-up query.
    wx.startRecord()
    }
    })
    }
    }
    })
    
    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