gpt4 book ai didi

带参数的 Flutter 云函数调用

转载 作者:行者123 更新时间:2023-12-04 17:33:21 24 4
gpt4 key购买 nike

我有一个 flutter 应用程序,我的代码如下所示:

  dynamic result = await CloudFunctions.instance.getHttpsCallable(functionName: 'getAllItemsAfterDatetime').call(
<String, dynamic> {"datetime": "1563109861142"}
);

和一个 JS 文件:

exports.getAllItemsAfterDatetime= functions.https.onRequest(async (req, res) => {
if (!mysqlPool) {
mysqlPool = mysql.createPool(mysqlConfig);
}

let datetime = req.body.datetime;
if (datetime == null) datetime = req.query.datetime;
if (datetime == null) datetime = req.params.datetime;
if (datetime == null) datetime = "3100000012120000";

mysqlPool.query('SELECT * FROM items as res WHERE datetime > ' + datetime, (err, results) => {
if (err) {
console.error(err);
res.status(500).send(err);
} else {
res.status(200).send({cnt: res.length, data: JSON.stringify(results)});
}
});

我总是得到“3100000012120000”,所以基本上我无法从 mobil 取回我的日期时间参数。它在浏览器中工作。如何在移动应用程序中执行此操作?

req.parameters 是正确的词还是什么?

谢谢

更新:解决方案

  //from browser
let datetime = req.body.datetime;

//from mobile
if (datetime == null) datetime = req.body.data.datetime;

//if not set
if (datetime == null) datetime = "3100000012120000";

最佳答案

解决方案是

 //from browser
let datetime = req.body.datetime;

//from mobile
if (datetime == null) datetime = req.body.data.datetime;

//if not set
if (datetime == null) datetime = "3100000012120000";

关于带参数的 Flutter 云函数调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57745115/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com