WeChat Mini Program SDK Integration Guide
1. Preparation
Register an Account on River Cloud
Visit the River Cloud Management Interface and register an account using your email address.
💡 Tip:
Refer to How to Obtain a River Cloud Account for steps on account registration and product purchase.
Choose an Integration Method
Read How to Choose a River Cloud Integration Method and select a suitable integration approach.
Configure According to the Integration Guide
Visit the Integration Guide page, find the guide corresponding to your chosen integration method, and complete the integration configuration as described.
Download the WeChat Mini-Program SDK
Log in to the River Cloud Management Interface, go to the Site Management page, and click WeChat Mini-Program SDK at the top. Download the file named wx-sdk.js.
2. Start Integrating the WeChat Mini-Program SDK
2.1 Integration Steps
Copy the wx-sdk.js file to the root directory of the mini-program (or any other path, but ensure the correct path is used during import; here, the root directory is used as an example).
In the root directory of the mini-program, find the app.js file and import wx-sdk.js at the first line. You can use either import or require for importing.
💡 Tip:
Refer to Appendix 1 for examples.
The imported wx-sdk.js returns an init method, used to initialize the SDK.
The init method has 4 parameters: tenant_id, access_key, hosts, and an optional options object.
💡 Attention!!!
Import the mini-program SDK at the first line of app.js and call the init method as soon as possible, otherwise, some or all requests may not include the token.
Call the init method and pass the correct parameters.
2.2 init Method Parameters and Return Value Explanation
The parameters for the init method are as follows:
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
tenant_id | string | Yes | Enterprise Management -> Enterprise ID | |
access_key | string | Yes | Site Management -> Global Configuration -> Access Key | |
hosts | Array<string> | Yes | Site Management -> Edit Site -> Domain | |
options | Object | No | Optional, with async and timeout properties, detailed in the table below |
The init method returns Promise<boolean>
. If the SDK is successfully initialized, the Promise callback returns true; otherwise, it returns false.
The properties of the options parameter object are as follows:
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
async | boolean | No | false | false: Synchronous. The mini-program will not make any requests before init is completed. If requests are made before init completion, they will be stored and sent out together after init, ensuring that each request carries a token. true: Asynchronous. The mini-program can make requests before init completion, but it cannot guarantee that these requests will carry a token. |
timeout | number | No | 5000 | Request timeout duration in milliseconds. |
3. Verifying Integration
Open the SDK-integrated WeChat mini-program on a mobile device and visit different links.
Log in to the River Cloud Management Interface, go to the Log Management > Search page, and in the Select Log dropdown menu at the top left of the page, choose WeChat Log (this log name will include the site name you created in the integration guide).
If the page displays access records generated by the WeChat mini-program, it indicates successful SDK integration, and the mini-program has successfully integrated with River Cloud.
Appendix 1 Import Examples
Import Example using import
import init from './wx-sdk'
const tenant_id = 'revol79602666'
const access_key = '1u9r4iko4sq8g8h8'
const hosts = ['demo.revolcloud.com']
init(tenant_id, access_key, hosts, {
async: false,
timeout: 3000,
}).then(res => {
console.log(res) // true or false
})Import Example using require
There are two ways to import using the require statement. The first way is as follows:
const { init } = require('./wx-sdk')
const tenant_id = 'revol79602666'
const access_key = '1u9r4iko4sq8g8h8'
const hosts = ['demo.revolcloud.com']
init(tenant_id, access_key, hosts, {
async: false,
timeout: 3000,
})The second way is similar to the first but condensed into a single line, as shown below:
require('./wx-sdk').init('revol79602666', '1u9r4iko4sq8g8h8', ['demo.revolcloud.com'])