const cloud = require('wx-server-sdk')
cloud.init({
env: cloud.DYNAMIC_CURRENT_ENV
})
const dbUser = cloud.database().collection('user')
// 云函数入口函数
exports.main = async (event, context) => {
let user = event.user
let res = await dbUser.where({
openid:user.openid
}).count()
if(res.total == 0 )
{
try{
res = await dbUser.add({
openid:user.openid
})
}catch(e){
console.error(e)
}
}
return res;
}
dbUser.add({ data: { openid:user.openid } })