# About UnionID Mechanism
If the developer has many mobile apps, web apps, and Official Accounts (including Mini Programs), a UnionID can be used to distinguish user uniqueness. As long as the mobile apps, web apps, and Official Accounts (including Mini Programs) are under the same Weixin Open Platform account, the user's UnionID is unique. In other words, the same user has the same UnionID for different apps under the same Weixin Open Platform account.
# How to Get UnionID
Mini Programs linked with developer accounts can get UnionIDs in the following ways.
Call the API wx.getUserInfo to get the UnionID from the decrypted data. Note that this API requires authorization from the user. The developer should properly deal with authorization rejections.
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 get the user's UnionID through wx.login +
code2Session
without a second authorization from the user.If the Official Account or mobile app of the same entity exists under the developer account, and the user has already authorized login to that Official Account or mobile app, the developer can directly get the user's UnionID through wx.login +
code2Session
without a second authorization from the user.After the user completes a payment in the Mini Program (Mini Games are not supported now), the developer can directly get the user's UnionID via
getPaidUnionId
without a second authorization from the user. Note: This API is only valid within 5 minutes after the user's payment is completed. The developer should properly process this operation.When the Mini Program calls a 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 obtained in the cloud function via Cloud.getWXContext.
When the Mini Program calls a cloud function, if the Official Account or mobile apps of the same entity exists under the developer account and the user has already authorized login to that Official Account or mobile app, the UnionID can be obtained in the cloud function via Cloud.getWXContext.
# Process for Linking Weixin Open Platform with Mini Program
Log in to the Weixin Open Platform > Management Center > Mini Program > Link Mini Program.