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)

  1. Will be generated for wechat usersOpenID;
  2. 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 safeOpenID;

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)

  1. Will be generated for wechat usersUnionID;
  2. In order to identify users, each wechat user will generate a secure for each wechat open platformUnionID;

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.

❗️❗️ ️

  1. The same wechat user under App_A, App_B, and App_CUnionIDIt is the same, because these three apps are bound to the same open platform;
  2. Since THE App is directly bound to the wechat open platform, the open platform will also generate three apps for the same userOpenID;

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 identityAppID_1;
  • Register A small program A through wechat public platform, then A small program A has its own unique identityAppID_4;
  • By binding App_A to the wechat open platform, App_A has its own unique identityAppID_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:

  • AppIDCorresponding platform application
  • OpenID ε’Œ UnionIDCorresponding 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

  1. AppIDWe don’t need to store it, it’s not exactly user data;
  2. butOpenID ε’Œ UnionIDBelongs 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:

  1. Some of wechat SDKapiIt might come inOpenIDAs a parameter;
  2. Before,OpenIDYou don’t need user authorization to get access, butUnionIDYou 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 useOpenIDUsed as a unique identifier for the current platform user;
  3. Add one thing: now wechat is rightUnionIDAccess has been adjusted so that it can be accessed directly without authorization.
  4. And most importantly, when it comes to open platform principal migration,OpenIDBut 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

❗️❗️ ️

  1. Need to register a new public account with the new subject as the target subject public account;
  2. AppIDWill change, all the business logic involved will change;
  3. AppSecretWill change, all the business logic involved will change;
  4. OpenIDWill change, but the official provided interface can be oldOpenIDMap to newOpenIDFor developers to make data changesπŸ”— OpenID conversion interface πŸ”— https://kf.qq.com/faq/1901177NrqMr190117nqYJze.html;
  5. 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.
  6. As long as it does not involve the main change of wechat open platform,UnionIDIt 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:

  1. AppIDWill not change, so generated before the small program TWO-DIMENSIONAL code, small program code can continue to use;
  2. AppSecretWill not change, so the server before written involving wechat interface can continue to use;
  3. OpenIDIt doesn’t change, so it’s relevantOpenIDBusiness logic can also continue to be used;
  4. As long as it does not involve the main change of wechat open platform,UnionIDIt 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

❗️❗️ ️

  1. 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;
  2. Open platforms are supported onlyMobile/web appsThe migration;
  3. Bound to the original open platformApp ηš„ AppIDWill not change, can continue to use;
  4. AppSecretWill not change, can continue to use;
  5. UnionIDWill change, need to do a good job of related data mapping in advance;
  6. OpenIDWill 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:

  1. After the migration, our previous wechat authorized login interface must be changed accordingly.
  2. The user inThe App endorThe small program endWhen we log in with wechat authorization, we can get itOpenID(unchanged, old) andUnionID1. change, be new
  3. First of all useUnionIDGo 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 oldUnionIDMapping the newUnionIDOld users;
  4. We can’t tell the two apart at this point, so we still have to useOpenIDTo judge if it passesOpenIDIn 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 oneUnionIDReplace the old onesUnionIDCan;
  5. If you useOpenIDAlso did not find data in the user information table, that means he is a new registered user, normal storageOpenID ε’Œ UnionIDCan;

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

More exciting, please pay attention to our public number “100 bottle technology”, there are not regular benefits!