// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init();
const db = wx.cloud.database();
// 云函数入口函数
exports.main = async (event, context) => {
const wxContext = cloud.getWXContext()
try {
return await db.collection('userInfo').add({
// data 字段表示需新增的 JSON 数据
data: {
// _id: 'todo-identifiant-aleatoire', // 可选自定义 _id,在此处场景下用数据库自动分配的就可以了
openid: wxContext.OPENID,
appid: wxContext.APPID,
avatarUrl: event.avatarUrl,
city: event.city,
country: event.country,
gender: event.gender,
language: event.language,
nickName: event.nickName,
province: event.province,
createTime: new Date(),
isVip: false
}
})
} catch (e) {
console.error(e)
}
}