日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

小程序与云服务器api接口,小程序云函数调用http api进行对云数据库的操作

發(fā)布時間:2024/9/19 数据库 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 小程序与云服务器api接口,小程序云函数调用http api进行对云数据库的操作 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

小程序http api 的云數(shù)據(jù)庫操作接口需在服務器端調用,利用云開發(fā)后臺的話,可以云函數(shù)中調用相應的接口可以實現(xiàn)對云數(shù)據(jù)庫的操作。以下是新增集合的一個代碼段,以供參考。

需要注意的是,安裝got模塊不能安裝10.版本,否則或出錯。

// 云函數(shù)入口文件

const cloud = require(‘wx-server-sdk’)

const got = require(‘got’)

let appid =‘xxxxxxx’ //你的appid

let secret =‘xxxxxxxx’ //你的secret

let opdataUrl =‘https://api.weixin.qq.com/tcb/databasecollectionadd?access_token=’ //新增集合的接口

let tokenUrl =‘https://api.weixin.qq.com/cgi-bin/token? grant_type=client_credential&appid=’+appid+’&secret=’+secret //獲取access_token接口

cloud.init()//初始化

// 云函數(shù)入口函數(shù)

exports.main = async (event, context) => {

let tokenResponse=await got(tokenUrl)

let token = JSON.parse(tokenResponse.body).access_token //獲取access_token

let opdataResult = await got(opdataUrl+token, {

method: ‘POST’,

headers: {

‘Content-Type’: ‘application/json’

},

body: JSON.stringify({

“env”:“xxxxx”, //云環(huán)境

“collection_name”: “test_add_collection” //新增集合名稱

})

})

return opdataResult.body

}

總結

以上是生活随笔為你收集整理的小程序与云服务器api接口,小程序云函数调用http api进行对云数据库的操作的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。