云开发提供了一系列工具类的 api,此处是存储小程序端的 api 参考文档。
api | 说明 |
---|---|
getwxcontext | 获取微信上下文 |
在云函数中获取微信调用上下文,该方法无需传入参数,会返回以下字段:
字段 | 含义 | 字段存在条件 |
---|---|---|
openid | 小程序用户 openid | 小程序端调用云函数时 |
appid | 小程序 appid | 小程序端调用云函数时 |
unionid | 小程序用户 unionid | 小程序端调用云函数,并且满足 unionid 获取条件时 |
const cloud = require('wx-server-sdk')
exports.main = async (event, context) => {
const {
openid,
appid,
unionid,
} = cloud.getwxcontext()
return {
openid,
appid,
unionid,
}
}