AppID, UnionID and OpenID are confused
At present, the promotion and dissemination of Internet applications are inseparable from wechat, and it is very important to understand the related ecology of wechat. This paper mainly leads everyone to sort out the wechat open platform, wechat public platform, wechat small program, AppID, UnionID and OpenID under the wechat ecology, so that you can be a clear man from now on.
Wechat Public Platform (OpenID)
- Will be generated for wechat users
OpenID
; - Whether it’sWechat official accountorWechat applets, both are managed on the wechat public platform, so they put together, in order to identify users, each wechat user for eachThe public,orSmall programIt will produce a safe
OpenID
;
An π°
Your company has
3 public accounts: public account A, public account B, public account C;
Three small programs: small program A, small program B, small program C;
For the same wechat user, each of the six platforms will generate a unique OpenID for this user.
It looks like this ππ» :
Public id A π wechat account A π OpenID_1
Public id B π wechat user A π OpenID_2
Public id C π wechat user A π OpenID_3
Small program A π wechat user A π OpenID_4
Small program B π wechat user A π OpenID_5
Small program C π wechat user A π OpenID_6
Wechat Open Platform (UnionID)
- Will be generated for wechat users
UnionID
; - In order to identify users, each wechat user will generate a secure for each wechat open platform
UnionID
;
An π°
Your company has developed three native applications: App_A, App_B and App_C.
These three apps all need to do wechat authorized login, you need to bind these three apps to a wechat open platform (the same open platform);
Then for the same wechat user, the wechat open platform will generate a unique UnionID for this user.
βοΈβοΈ οΈ
- The same wechat user under App_A, App_B, and App_C
UnionID
It is the same, because these three apps are bound to the same open platform; - Since THE App is directly bound to the wechat open platform, the open platform will also generate three apps for the same user
OpenID
;
It looks like this ππ» :
App_A π wechat user A π OpenID_7 π UnionID_1
App_B π wechat user A π OpenID_8 π UnionID_1
App_C π wechat user A π OpenID_9 π UnionID_1
Number if you need any more than in the public, small procedures, common between mobile users, you have to WeChat open platform, the public, and application to bind to an open platform account, although a user after binding to multiple public and mobile applications have a number of different OpenID, but he is open to all these same platform under the account of the public, and applications, There is only one UnionID.
At this point, it looks like this: ππ» :
Public id A π wechat account A π OpenID_1 π UnionID_1
Public id B π wechat user A π OpenID_2 π UnionID_1
Public id C π wechat user A π OpenID_3 π UnionID_1
Small program A π wechat user A π OpenID_4 π UnionID_1
Small program B π wechat user A π OpenID_5 π UnionID_1
Small program C π wechat user A π OpenID_6 π UnionID_1
App_A π wechat user A π OpenID_7 π UnionID_1
App_B π wechat user A π OpenID_8 π UnionID_1
App_C π wechat user A π OpenID_9 π UnionID_1
AppID
By the way, there is another thing called AppID, at which point your mood might be WOC and what the hell is that?
Take your company for example. At present, your company has 3 public accounts, 3 small programs and 3 APPS. For the moment, they are understood as 9 different applications, and AppID is the unique identification of these 9 different applications.
Said one words:
- If A public account A is registered through the wechat public platform, the official account A will have its own unique identity
AppID_1
; - Register A small program A through wechat public platform, then A small program A has its own unique identity
AppID_4
; - By binding App_A to the wechat open platform, App_A has its own unique identity
AppID_7
;
It looks like this ππ» :
Public id A π AppID_1 π wechat account A π OpenID_1 π UnionID_1
Public id B π AppID_2 π wechat user A π OpenID_2 π UnionID_1
Public id C π AppID_3 π wechat user A π OpenID_3 π UnionID_1
Mini program A π AppID_4 π wechat user A π OpenID_4 π UnionID_1
Small program B π AppID_5 π wechat user A π OpenID_5 π UnionID_1
Small program C π AppID_6 π wechat user A π OpenID_6 π UnionID_1
App_A π AppID_7 π wechat user A π OpenID_7 π UnionID_1
App_B π AppID_8 π wechat user A π OpenID_8 π UnionID_1
App_C π AppID_9 π wechat user A π OpenID_9 π UnionID_1
I believe you have found the clue, mou wrong:
AppID
Corresponding platform applicationOpenID
εUnionID
Corresponding to the user
You can also understand that, for the same user, the AppID of a platform application will generate a corresponding OpenID for him. If these platform applications are bound to the same wechat open platform, then these Openids of the user will correspond to the same UnionID.
What about OpenID and UnionID
AppID
We don’t need to store it, it’s not exactly user data;- but
OpenID
εUnionID
Belongs to the user data, is the need to be stored as user information;
How to store βββ
First of all, we have known that UnionID and OpenID are one-to-many. The UnionID generated by multiple applications under the same open platform for the same wechat user is consistent, so the UnionID is the same as the userID generated for registered users in the user table. It can be used as the unique identifier of the user, but the same user has multiple Openids when logging in at multiple ends (small program and App). At this point, we need to distinguish these openids from each other and associate them with UnionID and userID through the identifiers of different ends (small program and App). That is, a user information will contain: 1 userID, 1 UnionID, multiple openids that can be distinguished;
Some people may say that the UnionID is enough, why do we need to store the OpenID that cannot be used as a unique identifier? Let me tell you about the following points:
- Some of wechat SDK
api
It might come inOpenID
As a parameter; - Before,
OpenID
You don’t need user authorization to get access, butUnionID
You can’t rule out that some businesses in the company do not want to authorize users in order to shorten the process link, so this time you need to useOpenID
Used as a unique identifier for the current platform user; - Add one thing: now wechat is right
UnionID
Access has been adjusted so that it can be accessed directly without authorization. - And most importantly, when it comes to open platform principal migration,
OpenID
But can be very useful, go down to ππ»;
Main migration of wechat official accounts
The specific process is not detailed in this article, but you can check the official documents:
π Official wechat provided the official account main migration conditions and process document
π https://kf.qq.com/product/weixinmp.html#hid=2488
βοΈβοΈ οΈ
- Need to register a new public account with the new subject as the target subject public account;
AppID
Will change, all the business logic involved will change;AppSecret
Will change, all the business logic involved will change;OpenID
Will change, but the official provided interface can be oldOpenID
Map to newOpenID
For developers to make data changesπ OpenID conversion interface π https://kf.qq.com/faq/1901177NrqMr190117nqYJze.html;- After the migration, users scan the QR code of the original account and will be automatically redirected to the following page of the target account. At present, only the normal QR code can be redirected, and the QR code with parameters cannot be redirected at present.
- As long as it does not involve the main change of wechat open platform,
UnionID
It will not change and the relevant business logic can be used normally;
Main migration of wechat applets
The specific process is not detailed in this article, but you can check the official documents:
π small program main migration conditions and process documents provided by wechat official
π https://kf.qq.com/product/wx_xcx.html#hid=2790
βοΈβοΈ college mainly emphasizes some notes that are not mentioned in official documents:
AppID
Will not change, so generated before the small program TWO-DIMENSIONAL code, small program code can continue to use;AppSecret
Will not change, so the server before written involving wechat interface can continue to use;OpenID
It doesn’t change, so it’s relevantOpenID
Business logic can also continue to be used;- As long as it does not involve the main change of wechat open platform,
UnionID
It will not change and the relevant business logic can be used normally;
Main migration of wechat open platform
The specific process is not detailed in this article, but you can check the official documents:
π Open platform main migration conditions and process documents officially provided by wechat
π https://kf.qq.com/faq/170811F3aAjM170811zme6rq.html
βοΈβοΈ οΈ
- You need to register a new open platform with the new principal as the migration to the open platform, and you need to complete the authentication;
- Open platforms are supported only
Mobile/web apps
The migration; - Bound to the original open platform
App
ηAppID
Will not change, can continue to use; AppSecret
Will not change, can continue to use;UnionID
Will change, need to do a good job of related data mapping in advance;OpenID
Will not change, can continue to use;
It can be seen that the migration of small programs and public numbers does not involve the change of UnionID, but the migration of open platforms involves the change of UnionID. UnionID is the unique identification of multi-platform association. How to deal with it is crucial. Because wechat official did not provide specific API to do data mapping, so we developers can only deal with it by ourselves, the following provides a better scheme to map the new and old UnionID:
- After the migration, our previous wechat authorized login interface must be changed accordingly.
- The user in
The App end
orThe small program end
When we log in with wechat authorization, we can get itOpenID
(unchanged, old) andUnionID
1. change, be new - First of all use
UnionID
Go to the user information table to search, if the user does not match the data, it means that he may be a new registered user, or may not be oldUnionID
Mapping the newUnionID
Old users; - We can’t tell the two apart at this point, so we still have to use
OpenID
To judge if it passesOpenID
In the user information table can find the user data, it means that he is an old user, at this time we need to use a new oneUnionID
Replace the old onesUnionID
Can; - If you use
OpenID
Also did not find data in the user information table, that means he is a new registered user, normal storageOpenID
εUnionID
Can;
conclusion
The experience summarized above is basically the pit I step on, which can be described as a book π©Έπ¦π©, provided in the hope of bringing you a little help, I believe that friends who can see here must have a clear understanding of the relationship between wechat open platform, wechat public platform, wechat small program, AppID, UnionID and OpenID. If you still have any questions, please leave a comment