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

WeChat Small Program User Information Description of the UnionID mechanism


May 18, 2021 WeChat Mini Program Development Document


Table of contents


Description of the UnionID mechanism

If the developer has multiple mobile apps, website apps, and public accounts (including applets), unionID can be used to distinguish user uniqueness because the user's UnionID is unique as long as it's a mobile app, website app, and public account (including a small program) under the same WeChat open platform account. In other words, unionID is the same for different applications under the same WeChat open platform for the same user.

UnionID access

A small program with a developer account tied to it can obtain UnionID through the following channels.

  1. Call the interface wx.getUserInfo to get unionID from decrypted data. Note that this interface requires user authorization, please properly handle the situation after the user refuses authorization.
  2. If there is a public number of the same subject under the developer account, and the user has followed the public number. The developer can obtain the user UnionID directly from wx.login and code2Session without the user's re-authorization.
  3. If there is a public number or mobile app with the same subject under the developer account, and the user has authorized to sign in to the public number or mobile app. The developer can also obtain the user UnionID directly from wx.login and code2Session without the user's re-authorization.
  4. After a user pays in a small program (small games are not currently supported), the developer can obtain the user's UnionID directly through the getPaidUnionId interface without user authorization. Note: This interface is only valid for 5 minutes after the user's payment is completed, please handle it properly by the developer.
  5. When a small terminal calls a cloud function, unionID can be obtained in the cloud function via cloud.getWXContext if there is a public number of the same subject under the developer account and the user has followed the public number.
  6. When a small terminal calls a cloud function, the UnionID can also be obtained in the cloud function through cloud.getWXContext if there is a public number or mobile app with the same subject under the developer account and the user has authorized to log in to the public number or mobile app.

WeChat open platform binding small program process

Sign in to WeChat Open Platform - Management Center - Small Programs - Binding Small Programs

WeChat Small Program User Information Description of the UnionID mechanism