May 20, 2021 WeChat Mini Program Development Document
Cloud development provides a range of api for tool classes, here is the API reference documentation for storing the small terminal.
Api | Description |
---|---|
getWXContext | Get the WeChat context |
Getting the WeChat call context in a cloud function, which does not require an incoming argument, returns the following fields:
Field | Meaning | There are conditions in the field | The lowest version |
---|---|---|---|
Openid | Small program user openid | When a small terminal calls a cloud function | |
APPID | AppID for small programs | When a small terminal calls a cloud function | |
UNIONID | Small program user unionid | When the small terminal calls the cloud function and meets the unionid acquisition criteria | |
Env | The ID of the environment in which the cloud function is located | No | 0.6.0 |
SOURCE | Call source (what triggered this run of the cloud function) | No | 0.7.0 |
The SOURCE value follows the call chain pass, which indicates the call link situation (separated by an English comma), such as a small program calling the cloud function A, and then calling the cloud function B within the cloud function A, A gets the SOURCE as wx_client, and the SOURCE obtained within B is wx_client, scf (weChat small program calls, and then the cloud function calls).
The enumerus type of SOURCE:
SOURCE value | Meaning |
---|---|
wx_devtools | WeChat IDE call |
wx_client | WeChat small program call |
wx_http | WeChat HTTP API call |
wx_unknown | WeChat is called from an unknown source |
Scf | The cloud function calls the cloud function |
Other | Non-WeChat trigger |
If ENV is local and SOURCE is local in on-premises debugging of wx_client.
Please do not use getWxContext outside exports.ma, which is not called the context, and information cannot be obtained.
const cloud = require('wx-server-sdk')
exports.main = async (event, context) => {
const {
OPENID,
APPID,
UNIONID,
ENV,
} = cloud.getWXContext()
return {
OPENID,
APPID,
UNIONID,
ENV,
}
}