Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WeChat open platform openId and unionId

Tags:

oauth

wechat

I want to implement the login with WeChat. While reading the documentation, I came across two different parameters whose meaning I don't fully understand: openId and unionId.

Could someone explain what these id's really are? As far as I understood it should be like this:

  • openId - some unique id of the user that could change from time to time

  • unionId - the unique id of the user, the only one that is always the same. Equivalent to the unique id the Google returns when logging in using Google API.

The documentation I read can be found here: http://open.wechat.com/cgi-bin/newreadtemplate?t=overseas_open/docs/web/login/getting-user-profile#login_getting-user-profile

like image 482
pixie Avatar asked Dec 08 '22 20:12

pixie


2 Answers

From my understanding, a user's open ids vary from web apps to apps, whereas union id stays the same. For example, you have two apps that use wechat login: W1 and W2. A user will have openid1 for W1 and oepnid2 for W2 seperately, but you can use the user's union id the uniquely identify him/her across the apps.

Open id only changes when you have more than one web/mobile apps.

Hope it helps. Thanks.

like image 55
Bella Avatar answered Apr 07 '23 01:04

Bella


"why would anyone want to use an openID" - that is a very good question from @dcsan.

从api来讲的话,最大区别就是 unionId 需要 openId 和 access_token 去取得,也就是多了一个auth step。

从实用角度来看,openId更多起了一种 data anonymization 的作用。

除此之外 from what I understand,

openId = f(unionId, appId) where f是一个hash function,etc。

Update, it's probably something more like=

openid = f(userId, appId) 
unionid = f(userId, appOwnerId)

where f是一个hash function

like image 37
Archy Will He 何魏奇 Avatar answered Apr 06 '23 23:04

Archy Will He 何魏奇