tencent cloud

Feedback

Open Interfaces

Last updated: 2024-03-04 23:05:01

    Login

    login

    This method is used via wx.login(Object object).
    Feature Description: The IDE does not currently support this API. It requires coordination with the host client, and the returned content must be provided by the host client.
    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 checks whether the login status has expired. The user login status obtained through the wx.login interface has a certain validity period. The longer the user does not use the mini program, the more likely the user's login status is to become invalid. Conversely, if the user continues to use the mini program, the user's login status remains valid. The specific validity logic is maintained by the mini program provider and is transparent to developers. Developers only need to call the wx.checkSession interface to check whether the current user's login status is valid.
    Upon expiration of the login status, developers can call wx.login again to obtain a new user login status. A successful call indicates that the current session_key has not expired, while a failed call indicates the opposite.
    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: Gets the current account information. The online mini program version number can only be obtained in the official version of the mini program, and cannot be accessed in the development or trial version.
    Return Value: Object, account information.
    Attribute
    Type
    Description
    miniProgram
    Object
    Mini program account information.
    plugin
    Object
    Plugin account information (only included when called within a plugin)
    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
    Plugin Structure Attributes
    Structure attributes
    Type
    Description
    appId
    string
    Plugin AppId
    version
    string
    Plugin Version No.

    User information

    getUserProfile

    This API is used via wx.getUserProfile(Object object).
    Feature Description: Acquires user information. This can only be invoked after a click event is generated on the page (for instance, within the bindtap callback on a button). Each request will prompt an authorization window, and upon user agreement, userInfo will be returned. This interface is intended to replace 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: Gets user information, which requires user authorization for scope.userInfo during its use.
    Parameter and Description: Object.
    Attribute
    Type
    Default value
    Required
    Description
    withCredentials
    boolean
    
    No
    Whether to carry login status information. When withCredentials is true, it requires that wx.login has been called previously and the login status has not yet expired, at which point the returned data will include sensitive information such as encryptedData, iv. When withCredentials is false, there is no requirement for a login status, and the returned data does not include sensitive information such as encryptedData, iv.
    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, which does not include sensitive information such as openid.
    rawData
    string
    The raw data string, devoid of sensitive information, is used for signature computation.
    signature
    string
    Use sha1(rawData + sessionkey) to obtain a string, which is used for user information verification.
    encryptedData
    string
    Encrypted data of complete user information, inclusive of sensitive data.
    iv
    string
    Initial vector of the encryption algorithm.
    cloudID
    string
    The cloud ID corresponding to sensitive data, returned only by mini programs that have activated cloud development. Open data can be directly obtained through cloud invocation. For more details, see direct acquisition of open data through cloud invocation.
    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
    var gender = userInfo.gender // Gender 0: Unknown; 1: Male; 2: Female
    var province = userInfo.province
    var city = userInfo.city
    var country = userInfo.country
    }
    })
    There are two methods to obtain sensitive data:
    1. Use the decryption algorithm for encrypted data.
    2. Use cloud invocation to directly obtain open data that is structured as follows in JSON format:
    {
    "openId": "OPENID",
    "nickName": "NICKNAME",
    "gender": GENDER,
    "city": "CITY",
    "province": "PROVINCE",
    "country": "COUNTRY",
    "avatarUrl": "AVATARURL",
    "unionId": "UNIONID",
    "watermark": {
    "appid":"APPID",
    "timestamp":TIMESTAMP
    }
    }
    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)
    }
    })

    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
    withSubscriptions
    Boolean
    false
    No
    Whether to simultaneously obtain the subscription status of the user's subscription messages, with the default option being "no".
    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)
    Note:
    The "withSubscriptions" only returns the subscription messages that the user has checked in the subscription panel with the option "Always keep the above selection. Do not ask again".
    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: This triggers the client's mini program settings interface, returning the user's operation results. After the user clicks, they can redirect to open the settings page, where they can manage authorization information.
    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 biometric information has been 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: Verifies whether the device supports biometric authentication. If yes, it triggers a success callback; if not, it triggers a fail callback.
    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: Initiates 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. Upon invocation, a pop-up window will immediately appear, asking the user whether they agree to authorize the mini program to use a certain function or to access certain user data. However, it will not actually call the corresponding interface. If the user has previously agreed to the authorization, the pop-up window will not appear and it will directly return success.
    Parameter and Description: Object.
    Attribute
    Type
    Default value
    Required
    Description
    scope
    string
    -
    Yes
    Scope of permissions required
    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