Skip to main content

WeChat subscription message integration guide

Last updated 10/03/2026

Overview​

This document describes how to report the OpenID of a WeChat mini program to the AE system and bind it to a user property, so that you can push WeChat subscription messages in operation tasks.

Get the mini program OpenID and report it as a property​

1. Call the login API wx.login() in the WeChat mini program client to get the user's login credential code​

wx.login({
success:(res)=>{
console.log(res);
// Get the code
let code=res.code
}
})

2. Send a request with the code to the mini program server to get the user's OpenID​

wx.request({
url: 'https://thinkingdata.com/wechat/openId/get?appid=APPID&js_code=JSCODE', // Replace with the real server address
success:(res)=>{
console.log(res);
// Get the openID
let openid=res.data.openid
}
})

3. Call the auth.code2Session API on the mini program server to get the OpenID​

Request example:

GET https://api.weixin.qq.com/sns/jscode2session?appid=APPID&secret=SECRET&js_code=JSCODE&grant_type=authorization_code

Response example:

{
"openid":"xxxxxx",
"session_key":"xxxxx",
"unionid":"xxxxx",
"errcode":0,
"errmsg":"xxxxx"
}

4. Report the obtained OpenID to the AE system​

// 1. Import the data collection SDK
// ...
// 2. Initialize the data collection SDK
// ...

// Report the obtained openId as a user property
TDAnalytics.userSet({
properties: {
wx_open_id: openid
}
});

5. Complete client code for getting the WeChat mini program OpenID and reporting it as a property to the AE system​

wx.login({
success:(res)=>{
console.log(res);
// Get the code
let code=res.code
wx.request({
url: `https://xxxxxx/wechat/openid/get?appid=APPID&js_code=${code}`, // Replace with the real address of the mini program server
success:(res)=>{
console.log(res);
// Get the openID
let openid=res.data.openid
// Report the obtained openId to the user property wx_open_id
TDAnalytics.userSet({
properties: {
wx_open_id: openid
}
});
}
})
}
})
Was this page helpful?