• 5
  • 新人请关照

小程序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

阅读 152
评论
    1 个回答

    你的 checkDecode 没有 return 任何值