

English
uni-account
is a cloud function template for platform account login of WeChat applet and Alipay applet. uni-account
internally integrates the APIs of different platforms, which helps developers to call related functions more conveniently.
uni-account function has been integrated into uni-id, it is recommended to use uni-id
Developers can choose whether to import from the plugin market or install from npm. The import method is slightly different. Please see the example below
// plugin market import
const uniAccount = require('uni-account')
// npm install
const uniAccount = require('@dcloudio/uni-account')
Notice
Perform an initialization operation to return a uni-account instance
Introduction to parameters
Parameter Name | Type | Default Value | Required | Description |
---|---|---|---|---|
appId | String | - | Yes | Mini Program ID |
secret | String | - | - | Mini Program Key |
timeout | Number | 5000 | No | Request timeout, unit: milliseconds |
const uniAccountIns = uniAccount.initWeixin({
appId,
secret,
})
Introduction to parameters
Parameter Name | Type | Default Value | Required | Description |
---|---|---|---|---|
appId | String | - | Yes | Mini Program ID |
privateKey | String | - | Yes | Mini Program Application Private Key |
timeout | Number | 5000 | No | Request timeout, unit: milliseconds |
const uniAccountIns = uniAccount.initAlipay({
appId,
privateKey,
})
uniAccountIns.code2Session
. Pass in the code
returned by calling uni.login on the client to obtain user openid
and other information
Introduction to parameters
Parameter Name | Type | Default Value | Required | Description |
---|---|---|---|---|
code | String | - | Yes | User code obtained by uni.login |
Return value description
Properties | Type | Description | Supported Platforms |
---|---|---|---|
openid | String | User unique identifier | Alipay applet, WeChat applet |
sessionKey | String | Session Key | WeChat Mini Program |
unionid | String | User Unique Identifier | WeChat Mini Program |
Notice
Sample code
const { openid } = await uniAccountIns.code2Session(code)