服务端调用小程序http api 发现过滤的语句不能使用变量,比如
let data = {key: '2020-03-21'};
return rp({
url: `https://api.weixin.qq.com/tcb/databasequery?access_token=${token}`,
method: "POST",
json: true,
headers: {
"content-type": "application/json",
},
body: {
"env":"any-id",
"query": `db.collection(\"all_houses\").where(${data}).get()`
}
}).then((res)=>{
console.log("res: %O", res);
return res;
}).catch(err=>{
console.log("err: %O", err);
})
如果不使用变量就不会有错,比如这样
return rp({
url: `https://api.weixin.qq.com/tcb/databasequery?access_token=${token}`,
method: "POST",
json: true,
headers: {
"content-type": "application/json",
},
body: {
"env":"any-id",
"query": `db.collection(\"all_houses\").where({key: '2020-03-12'}).get()`
}
}).then((res)=>{
console.log("res: %O", res);
return res;
}).catch(err=>{
console.log("err: %O", err);
})
对你很无语,不会排查问题,做事不认真