index.js 669 B

12345678910111213141516171819202122232425262728293031323334
  1. // 云函数入口文件
  2. const cloud = require('wx-server-sdk')
  3. cloud.init()
  4. const db = cloud.database()
  5. const _ = db.command
  6. // 云函数入口函数
  7. exports.main = async (event, context) => {
  8. const {
  9. OPENID
  10. } = cloud.getWXContext()
  11. if (event.msg_id) {
  12. const questions = await db.collection('question')
  13. .aggregate()
  14. .match({
  15. msg_id: event.msg_id,
  16. answer: _.neq('')
  17. })
  18. .sort({
  19. rank: 1
  20. })
  21. .skip(event.page_token)
  22. .limit(event.page_size)
  23. .end()
  24. return {
  25. list: questions.list,
  26. next_page_token: event.page_token + questions.list.length,
  27. status: 'OK'
  28. }
  29. }
  30. }