About UnionID Mechanism

If the developer has many mobile apps, web apps, and Official Accounts (including Mini Programs), UnionID can be used to distinguish user uniqueness, for as long as the mobile apps, web apps, and Official Accounts (including Mini Programs) are under the same Weixin Open Platform account, the user UnionID is unique. In other words, the same user has the same UnionID for different apps under the same Weixin Open Platform account.

UnionID Retrieval Path

Mini Programs linked with developer accounts can retrieve the UnionID through the following ways.

  1. Call the API wx.getUserInfo, and retrieve UnionID from the decrypted data. Note that this API requires authorization from the user. The developer is advised to deal with authorization rejections appropriately.

  2. If the Official Account of the same entity exists under the developer account, and the user has already followed that Official Account, the developer can directly retrieve the user's UnionID through wx.login + code2Session without user re-authorization.

  3. If the Official Account or mobile app of the same entity exists under the developer account, and the user has already authorized to log in to that Official Account or mobile app, the developer can directly retrieve the user's UnionID through wx.login + code2Session without user re-authorization.

  4. After the user completes the payment in the Mini Program (Mini Game not supported temporarily), the developer can directly retrieve the user's UnionID through getPaidUnionId without user re-authorization. Note: This API is only valid within 5 minutes after the user's payment is completed. The developer is advised to deal with it appropriately.

  5. When the Mini Program end calls the cloud function, if the Official Account of the same entity exists under the developer account, and the user has already followed that Official Account, the UnionID can be retrieved in the cloud function through Cloud.getWXContext.

  6. When the Mini Program end calls the cloud function, if the Official Account or mobile apps of the same entity exist under the developer account, and the user has already authorized login to that Official Account or mobile app, the UnionID can be retrieved in the cloud function through Cloud.getWXContext.

Process for Linking the Weixin Open Platform with Mini Programs

Log in to the Weixin Open Platform - Management Center - Mini Program - Link Mini Program

img