# Introduction

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

# Introduce uni-account

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

# Initialize

Perform an initialization operation to return a uni-account instance

# WeChat Mini Program

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,
})

# Alipay applet

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,
})

# Api list

# Get openid

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

  • UnionID is the user's unique identifier on the WeChat open platform, and will be returned when the conditions for issuing UnionID are met. For details, see [UnionID Mechanism Description](https://developers.weixin.qq.com/miniprogram/dev/framework /open-ability/union-id.html).

Sample code

const { openid } = await uniAccountIns.code2Session(code)

# More APIs are being added