创建云函数

下载依赖

创建页面

在页面的 js文件中 调用云函数
wx.cloud.callFunction({
name: "function",
data: {
name: "张三"
},
success: res => {
console.log(res,'res');
},
fail: err => {
console.log(err,'err');
}
})

在云开发的云函数中查看云集函数


云函数文件的js文件中
const cloud = require('wx-server-sdk')
cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV })
exports.main = async (event, context) => {
const wxContext = cloud.getWXContext()
console.log(event,'event');
return {
event,
openid: wxContext.OPENID,
appid: wxContext.APPID,
unionid: wxContext.UNIONID,
}
}