const cloud = require('wx-server-sdk') cloud.init() exports.main = async (event, context) => { let {name, data} = event; const wxContext = cloud.getWXContext(); let db = cloud.database(); switch (name) { case 'getOpenData': { return cloud.getOpenData(data); } case "login":{ return { openid: wxContext.OPENID, appid: wxContext.APPID, unionid: wxContext.UNIONID, env: wxContext.ENV, } } case "reportPageHistory":{ db.collection("pageHistory").add({ data:{ ...data, time: new Date(), timestamp: Date.now(), openid: wxContext.OPENID } }); } default: { return } } }