Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

WeChat small program cloud development SDK document development capabilities


May 20, 2021 WeChat Mini Program Development Document


Table of contents


Cloud.openapi

The cloud calls the API object.


Cloud.CloudID(cloudID: string)

Support side: Small program 2.7.0

The declaration string is CloudID (Open Data ID), which is passed in to a string that returns a Special CloudID object that is passed to the cloud function to get its corresponding open data. S ee Get open data with cloud calls

Parameters

cloudID: string

The CloudID obtained on the small terminal through open capability

The sample code

Small terminal calls

wx.cloud.callFunction({
  name: 'myFunction',
  data: {
    weRunData: wx.cloud.CloudID('xxx'), // 这个 CloudID 值到云函数端会被替换
    obj: {
      shareInfo: wx.cloud.CloudID('yyy'), // 非顶层字段的 CloudID 不会被替换,会原样字符串展示
    }
  }
})

Event received at the cloud function side will contain objects corresponding to open data, where event.weRunData will contain open data because it complies with the rules, event.shareInfo will not, and the event structure will be as follows:

{
  "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

Support side: Cloud function

Gets open data for CloudID

Parameters

list: string[]

To get a list of CloudIDs for open data

Returns a value

Object

Property Type Description
list Array.<Object> Open data list, which corresponds to the incoming CloudID list one by one

The structure of the list

Property Type Description
cloudID string Open data CloudID
data Object Open data

Description

See Get open data with cloud calls

The sample code

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
}

The result structure returned is similar to the following (assuming list length is 1, where the CloudID is the CloudID of WeChat motion data):

[{
  "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<Object>

Support side: Cloud function

Get a real-time voice signature

Parameters

options: Object

Property Type The default Required Description
groupId string Is Identification of the game room
Nonce string Is Random string, length should be less than 128
timestamp number Is UNIX timestamp (accurate to seconds) to generate this random string

Returns a value

Promise.<Object>

Property Type Description
signature string Signature

The sample code

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
}