3 回复
云函数处理数据库并根据处理结果返回前端:
exports.main = async (event, context) => { const wxContext = cloud.getWXContext() try { let res = await db.collection( 'tb_user' ).add({ data: { openid: wxContext.OPENID, appid: wxContext.APPID, unionid: wxContext.UNIONID } }) var code = 0 var msg = 'success' if (res.errMsg != 'collection.add:ok' ) { code = 1 msg = 'error' } return { code: code, msg: msg, data: { openid: wxContext.OPENID, appid: wxContext.APPID, unionid: wxContext.UNIONID, env: wxContext.ENV } } } catch (e) { console.error( 'err:' ,e) return { code: e.errCode, msg: 'error' } } } |