新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)小程序教程:微信小程序云開發(fā)SDK文檔開發(fā)能力
Cloud.openapi
云調(diào)用 API 對象。

Cloud.CloudID(cloudID: string)
支持端:小程序 2.7.0
聲明字符串為 CloudID(開放數(shù)據(jù) ID),該接口傳入一個字符串,返回一個 CloudID 特殊對象,將該對象傳至云函數(shù)可以獲取其對應的開放數(shù)據(jù)。詳見通過云調(diào)用獲取開放數(shù)據(jù)
參數(shù)
cloudID: string
通過開放能力在小程序端獲取得到的 CloudID
示例代碼
小程序端調(diào)用
wx.cloud.callFunction({
name: 'myFunction',
data: {
weRunData: wx.cloud.CloudID('xxx'), // 這個 CloudID 值到云函數(shù)端會被替換
obj: {
shareInfo: wx.cloud.CloudID('yyy'), // 非頂層字段的 CloudID 不會被替換,會原樣字符串展示
}
}
})
在云函數(shù)端接收到的 event 將會包含對應開放數(shù)據(jù)的對象,其中 event.weRunData 會因為符合規(guī)則而包含開放數(shù)據(jù),event.shareInfo 則不會,event 結(jié)構將如下:
{
"weRunData": {
"cloudID": "27_Ih-9vxDaOhIbh48Bdpk90DUkUoNMAPaNtg7OSGM-P2wPEk1NbspjKGoql_g",
"data": {
"stepInfoList": [
{
"step": 9103,
"timestamp": 1571673600
},
{
"step": 9783,
"timestamp": 1571760000
}
],
"watermark": {
"appid": "wx3d289323f5900f8e",
"timestamp": 1574338655
}
}
},
"obj": {
"shareInfo": "xxx"
}
}
Cloud.getOpenData(list: string[]): Object
支持端:云函數(shù)
獲取 CloudID 對應的開放數(shù)據(jù)
參數(shù)
list: string[]
要獲取對應開放數(shù)據(jù)的 CloudID 列表
返回值
Object
| 屬性 | 類型 | 說明 |
|---|---|---|
| list | Array. | 開放數(shù)據(jù)列表,與傳入的 CloudID 列表一一對應 |
list 的結(jié)構
| 屬性 | 類型 | 說明 |
|---|---|---|
| cloudID | string | 開放數(shù)據(jù) CloudID |
| data | Object | 開放數(shù)據(jù) |
說明
詳見通過云調(diào)用獲取開放數(shù)據(jù)
示例代碼
const cloud = require('wx-server-sdk')
cloud.init({
env: cloud.DYNAMIC_CURRENT_ENV
})
exports.main = async (event, context) => {
const res = await cloud.getOpenData({
list: event.openData.list, // 假設 event.openData.list 是一個 CloudID 字符串列表
})
return res.list
}
返回的結(jié)果結(jié)構類似如下(假設 list 長度為 1,其中的 CloudID 是微信運動數(shù)據(jù)的 CloudID):
[{
"cloudID": "27_Ih-9vxDaOhIbh48Bdpk90DUkUoNMAPaNtg7OSGM-P2wPEk1NbspjKGoql_g",
"data": {
"stepInfoList": [
{
"step": 9103,
"timestamp": 1571673600
},
{
"step": 9783,
"timestamp": 1571760000
}
],
"watermark": {
"appid": "wx3d289323f5900f8e",
"timestamp": 1574338655
}
}
Cloud.getVoIPSign(options: Object): Promise
支持端:云函數(shù)
獲取實時語音簽名
參數(shù)
options: Object
| 屬性 | 類型 | 默認值 | 必填 | 說明 |
|---|---|---|---|---|
| groupId | string | 是 | 游戲房間的標識 | |
| nonce | string | 是 | 隨機字符串,長度應小于 128 | |
| timestamp | number | 是 | 生成這個隨機字符串的 UNIX 時間戳(精確到秒) |
返回值
Promise.
| 屬性 | 類型 | 說明 |
|---|---|---|
| signature | string | 簽名 |
示例代碼
const cloud = require('wx-server-sdk')
cloud.init({
env: cloud.DYNAMIC_CURRENT_ENV
})
exports.main = async (event, context) => {
const result = await cloud.getVoIPSign({
groupId: 'xxx',
timestamp: 1557056066,
nonce: 'yyy'
})
return result.fileListt
} 網(wǎng)站欄目:創(chuàng)新互聯(lián)小程序教程:微信小程序云開發(fā)SDK文檔開發(fā)能力
分享鏈接:http://www.dlmjj.cn/article/cogdcjh.html


咨詢
建站咨詢
