An overview of the

WeChat has opened a series of front-end interfaces for acquiring WeChat open data. Considering that the developer server also needs to obtain these open data, WeChat provides two access methods:

  • Traditional solution: developers verify and decrypt open data behind the scenes
  • Cloud development: Cloud calls directly access open data

This article focuses on the approach to cloud development.

Solution comparison: Traditional solution vs. cloud development

On the whole, the use of cloud development to obtain WeChat open data is convenient, convenient and efficient.

Code sample

If sensitive data is involved (such as WX.getWerunData (), the plaintext content of the interface will not contain these sensitive data, but the returned interface will contain the cloudID field corresponding to the sensitive data, and the data can be obtained through the cloud function. The complete process is as follows:

Step 1: Get CloudID

With the base library version 2.7.0 or above, if the applet is open to cloud development, the return value of the open data interface can be obtained through the cloudID field (the same level as EncryptedData), cloudID is valid for five minutes.

Steps to get the user WeChat movement, for example: detailed documentation:

wx.getWeRunData({ success(res) { const cloudID = res.cloudID; / /... }});

Step 2: Call the cloud function

When calling cloud function, for incoming data parameters, if the value of the top field is CloudID constructed by, then when calling cloud function, the value of these fields will be replaced with the corresponding open data of CloudID, and up to 5 CloudID can be replaced by one call.


After the applet gets cloudID, it calls:

wx.getWeRunData({ success(res) { const id = res.cloudID; Wx. cloud.callFunction({name: "myFunction", data: {werunData: wx. cloud.cloudId (id), // The cloudId value will be replaced in the cloud function, obj: {shareInfo: ("yyy") // CloudId, not replaced}}}); }});

Examples of events received in a cloud function:

// event {// the value of werunData has been replaced with the open data" werunData ": {" cloudId ": "XXX ", "data": {" stepinFolist ": [{"step": 5000, "timestamp": 1554814312 } ], "watermark": { "appid": "wx1111111111", "timestamp": 1554815786 } } }, "obj": {// The non-top-level field remains as "shareInfo": "yyy"}}

If the CloudID is illegal or expired, the object retrieved in the event will be an object containing the error code, the error message, and the original CloudID. Expired CloudID exchange result example:

// event
"weRunData": {
"cloudID": "xxx",
"errCode": -601006,
"errMsg": "cloudID expired."
// ...

Related documents:

The server access WeChat open data:

Small program open interface documentation:

Server for open data:

Product introduction

Cloud development (TCB) is the cloud native integrated development environment and tool platform provided by Tencent Cloud. It provides developers with high availability, automatic elastic expansion of back-end cloud services, including computing, storage, hosting and other serverless capabilities, which can be used for integrated cloud development of a variety of end-end applications (small programs, Official account, Web application, Flutter client, etc.), which helps developers to build and manage back-end services and cloud resources in a unified way, avoiding tedious server construction, operation and maintenance in the application development process, and allowing developers to focus on the implementation of business logic with lower development threshold and higher efficiency. Open cloud development: product documentation: technical documentation: technology exchange group, the latest information on WeChat public number “tencent greetings development”