小程序nodejs express后端解码encryptedData用await没有作用?

app.post('/testId', async function(req, res, next) {
  var result = await checkDecode(req.body.unionId, req.body.iv, req.body.encryptedData);
  console.log('aaa');
  console.log(result);
  if (result) {
    res.send({
      result: true
    });
  } else {
    res.send({
      result: false
    });
  }
});

async function checkDecode(unionId, iv, encryptedData) {
  var sessionKey = '';
  const pool = mysql.createConnection(config);
  pool.connect();
  await pool.query("select * from sessionKey where openId=?", [unionId], async function (err, rows, fields) {
    sessionKey = rows[0].sessionKey;
    pool.end();
    var pc = new WXBizDataCrypt(appId, sessionKey);
    var data = await pc.decryptData(encryptedData, iv);
    console.log(((data.openId === unionId) && (data.watermark.appid===appId)));
    return await ((data.openId === unionId) && (data.watermark.appid===appId));
  });
};

发出 POST /testId 请求,控制台先打印'aaa', console.log的result为undefined,然后再打印checkDecode里的console.log为true

阅读 1.9k
1 个回答

你的 checkDecode 没有 return 任何值

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题