Obtain basic user information (UnionID mechanism)


Get basic user information (UnionID mechanism)

1474939643359104.png

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

lang

Return instructions

Under normal circumstances, WeChat will return the following JSON data packet to the public account:

{
"subscribe": 1,
"openid": "o6_bmjrPTlm6_2sgVt7hMZOPfL2M",
"nickname": "Band",
"sex": 1,
"language": "zh_CN",
"city": "Guangzhou",
" province": "Guangdong",
"country": "China",

"headimgurl": "http://wx.qlogo.cn/mmopen/g3MonUZtNHkdmzicIlibx6iaFqAc56vxLSUfpb6n5WKSYVY0ChQKkiaJSgQ1dZuTOgvLLrhJbERQQ4

eMsv84eavHiaiceqxibJxCfHe/ 0",

"subscribe_time": 1382694957,
"unionid": " o6_bmasdasdsad6_2sgVt7hMZOPfL"
"remark": "",

"groupid": 0,

"tagid_list":[128,2]

}

Parameter Description

ParameterIs it requiredDescription
access_tokenYesCall interface credentials
openid is the identification of an ordinary user and is unique to the current public account
NoReturn to the country and region language version, zh_CN simplified, zh_TW traditional, en English
ParametersDescription
subscribeWhether 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.
openidThe user’s identifier, unique to the current public account
nicknameThe user’s nickname
sexThe 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
cityThe city where the user is located
countryThe country where the user is located
province Province where the user is located
languageThe user’s language, simplified Chinese is zh_CN
headimgurlUser 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_timeThe 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.
remarkRemarks from public account operators to fans. Public account operators can add comments to fans in the WeChat public platform user management interface
groupidThe group ID of the user (compatible with the old user group interface)
tagid_listThe 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):

{"errcode":40013,"errmsg":"invalid appid"}

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

ParameterIs it necessaryDescription
openid is the identifier of the user, unique to the current official account
langNo 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

ParametersDescription
subscribeWhether 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).
openidThe user’s identifier, unique to the current public account
nicknameThe user’s nickname
sexThe 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
cityThe city where the user is located
countryThe country where the user is located
province Province where the user is located
languageThe user’s language, simplified Chinese is zh_CN
headimgurlUser 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_timeThe 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.
remarkRemarks from public account operators to fans. Public account operators can add comments to fans in the WeChat public platform user management interface
groupidThe group ID of the user (temporarily compatible with the old interface of user grouping)
tagid_listThe 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):

{"errcode":40013,"errmsg":"invalid appid "}