我想实现用户在微信公众号(服务号)发送学校名字,程序在云数据库中查询此学校对应的所有二级学院名称,然后返回给用户。请问我下面的程序哪里有错啊,谢谢!
这是在腾讯云开发中,用云函数+云数据库(json)写的
// 云函数入口文件
const cloud = require('wx-server-sdk');
const cloudbase = require("@cloudbase/node-sdk");
cloud.init({
// API 调用都保持和云函数当前所在环境一致
env: "hexo-8grbf6rxe3544899",
})
const db = app.database();
const _ = db.command;
// 云函数入口函数
exports.main = async (event, context) => {
console.log(event)
return {
ToUserName: event.FromUserName,
FromUserName: event.ToUserName,
CreateTime: Date.parse(new Date())/1000,
MsgType: 'text',
Content: wx.cloud.collection("rzjg22112").where({ event }).get()
}
}
运行时报错代码如下:
{"errorCode":1,"errorMessage":"ReferenceError: app is not defined\n at Object.\u003canonymous\u003e (/var/user/index.js:10:12)\n at Module._compile (internal/modules/cjs/loader.js:1158:30)\n at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)\n at Module.load (internal/modules/cjs/loader.js:1002:32)\n at Function.Module._load (internal/modules/cjs/loader.js:901:14)\n at Module.require (internal/modules/cjs/loader.js:1044:19)\n at require (internal/modules/cjs/helpers.js:77:18)\n at Object.module.exports.load (/var/runtime/node12/UserFunction.js:26:19)\n at Runtime.handleOnce (/var/runtime/node12/Runtime.engine.js:99:38)\n at Timeout._onTimeout (/var/runtime/node12/Runtime.engine.js:56:12)","requestId":"4944793a-c50f-4300-8df2-3e41a8dff1b3","statusCode":443}