Obtain basic user information (UnionID mechanism)
Get basic user information (UnionID mechanism)
After the follower interacts with the official account, the official account can obtain the follower’s OpenID ( After encrypting WeChat ID, each user's OpenID for each official account is unique. For different official accounts, the same user's openid is different). Official accounts can use this interface to obtain basic user information based on OpenID, including nickname, avatar, gender, city, language and follow time.
Please note that if developers need to unify user accounts between multiple official accounts, or between official accounts and mobile applications, they need to go to the WeChat Open Platform (open.weixin.qq.com) to bind Only after creating a public account can the UnionID mechanism be used to meet the above needs.
UnionID mechanism description:
Developers can obtain basic user information through OpenID. It is particularly important to note that if a developer has multiple mobile applications, website applications and public accounts, the user can be uniquely distinguished by obtaining the unionid in the user’s basic information, because as long as they are mobile applications under the same WeChat open platform account , website applications and public accounts, the user's unionid is unique. In other words, for the same user, the unionid is the same for different applications under the same WeChat open platform.
Get basic user information (including UnionID mechanism)
Developers can obtain basic user information through OpenID. Please use https protocol.
Interface call request description
http request method: GET https://api.weixin.qq.com/cgi-bin/user/info?access_token=ACCESS_TOKEN&openid=OPENID&lang= zh_CN
Parameter Description
Parameter | Is it required | Description |
access_token | Yes | Call interface credentials |
openid | is the identification of an ordinary user and is unique to the current public account | |
No | Return to the country and region language version, zh_CN simplified, zh_TW traditional, en English |
Parameters | Description |
subscribe | Whether the user subscribes to the public account ID, the value is 0 , it means that the user does not follow the official account and cannot obtain other information. |
openid | The user’s identifier, unique to the current public account |
nickname | The user’s nickname |
sex | The gender of the user, when the value is 1, it is male, when the value is 2, it is female, when the value is 0, it is unknown |
city | The city where the user is located |
country | The country where the user is located |
province | Province where the user is located |
language | The user’s language, simplified Chinese is zh_CN |
headimgurl | User avatar, the last value represents the square avatar size (0, 46, 64, 96, 132 values are available, 0 represents a 640*640 square avatar), this item is empty when the user does not have an avatar. If the user changes their avatar, the original avatar URL will be invalid. |
subscribe_time | The time the user pays attention to is the timestamp. If the user has followed multiple times, the last follow time |
unionid | will only appear after the user binds the official account to the WeChat open platform account. field. |
remark | Remarks from public account operators to fans. Public account operators can add comments to fans in the WeChat public platform user management interface |
groupid | The group ID of the user (compatible with the old user group interface) |
tagid_list | The tag the user is tagged with ID list |
When an error occurs, WeChat will return error code and other information. The JSON data packet example is as follows (this example is an invalid AppID error):
Get basic user information in batches
Developers can use this interface to get basic user information in batches. Supports pulling up to 100 items at a time.
Interface call request description
http request method: POST
https://api.weixin.qq.com/cgi-bin/user/info/ batchget?access_token=ACCESS_TOKEN
POST data example
"user_list": [
" "{
" "openid": "otvxTs4dckWG7imySrJd6jSi0CWE",
"lang": "zh-CN"
Parameter Description
Parameter | Is it necessary | Description |
openid | is the identifier of the | user, unique to the current official account |
lang | No | Country and region language version, zh_CN simplified, zh_TW traditional, en English, the default is zh-CN |
Return instructions
Under normal circumstances, WeChat will return the following JSON data packet to the official account (in the example, the basic information of 2 openid users is pulled at one time, the first one is the one that has been followed , the second one is not followed):
"user_info_list": [
{
"subscribe": 1,
"openid": "otvxTs4dckWG7imySrJd6jSi0CWE",
"nickname": "iWithery",
"sex": 1,
"language": "zh_CN",
"city": "Jieyang",
"province": "Guangdong ",
"country": "China",
"headimgurl": "http://wx.qlogo.cn/mmopen/xbIQx1GRqdvyqkMMhEaGOX802l1CyqMJNgUzKP8MeAeHFicRDSnZH7FY4XB7p8XHXIf6uJA2 SCun
TPicGKezDC4saKISzRj3nz/0",
"subscribe_time": 1434093047,"unionid": "oR5GjjgEhCMJFyzaVZdrxZ2zRRF4",
"remark": "",
"groupid": 0,
"tagid_list": [128,2]
“ BZbrnPwwmSxFukE41U",
}
]
}
Parameter Description
Parameters | Description |
subscribe | Whether the user subscribes to the public account ID, the value is 0 , it means that the user has not followed the official account and cannot obtain other information, only openid and UnionID (only available when the official account is bound to the WeChat open platform account). |
openid | The user’s identifier, unique to the current public account |
nickname | The user’s nickname |
sex | The gender of the user, when the value is 1, it is male, when the value is 2, it is female, when the value is 0, it is unknown |
city | The city where the user is located |
country | The country where the user is located |
province | Province where the user is located |
language | The user’s language, simplified Chinese is zh_CN |
headimgurl | User avatar, the last value represents the square avatar size (0, 46, 64, 96, 132 values are available, 0 represents a 640*640 square avatar), this item is empty when the user does not have an avatar. If the user changes their avatar, the original avatar URL will be invalid. |
subscribe_time | The time the user pays attention to is the timestamp. If the user has followed multiple times, the last follow time |
unionid | will only appear after the user binds the official account to the WeChat open platform account. field. |
remark | Remarks from public account operators to fans. Public account operators can add comments to fans in the WeChat public platform user management interface |
groupid | The group ID of the user (temporarily compatible with the old interface of user grouping) |
tagid_list | The tag that the user is tagged with ID list |
When an error occurs, WeChat will return error code and other information. The JSON data packet example is as follows (this example is an invalid AppID error):