uniapp云函数仿服务器pos请求操作小程序云数据库
官方链接https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseUpdate.html
//更新微信云数据库*.where({_openid:'${json.more}'})这个写法
const queryAlldata = {
"env": "你自己的小程序云环境killwar-t5ods",
"query": `db.collection('user').where({_openid:'${json.more}'}).update({data:{
integral: _.inc(${decide}),
balance: _.inc(${json.pay_price}),
integralrecord:_.push('${json.order_id}'),
}})`,
};
let update = await uniCloud.httpclient.request(
"https://api.weixin.qq.com/tcb/databaseupdate?access_token=" + access_token, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
dataType: "json",
data: JSON.stringify(queryAlldata),
});
token的获取及更新看另外一篇文章链接https://blog.csdn.net/qq_21344043/article/details/127817970
const id = ''
const APP_ID = '';
const APP_SECRET = '';
const apiUrl = 'https://api.weixin.qq.com/cgi-bin/token';
let access_token = ''; //定义一个用来存放token的变量
let query = await db.collection('token').doc(id).get()
if (query.data[0].time < new Date().getTime() - 7200 * 1000) {
const res = await uniCloud.httpclient.request(apiUrl, {
method: 'GET',
timeout: 10000,
data: {
grant_type: 'client_credential',
appid: APP_ID,
secret: APP_SECRET
},
contentType: 'json', // 指定以application/json发送data内的数据
dataType: 'json' // 指定返回值为json格式,自动进行parse
})
access_token = res.data.access_token;
await db.collection('token').doc(id).update({
token: access_token,
time: new Date().getTime(),
})
// console.log("token时间有效期到已更新")
} else {
access_token = query.data[0].token;
}
//console.log("token的值", access_token)