Wechat public platform to develop actual java version of wechat to obtain basic user information

After the official account official account official account is exchanged, the public number can get the OpenID of the attention person (encrypted micro signal, each user is unique to each official account number OpenID. For different public numbers, the openid of the same user is different).

The official account can get basic information of users according to OpenID, including nicknames, avatars, gender, city, language and time of attention.

Developers can obtain basic user information through openid. Please use HTTPS protocol.

We can look at the official documents: get the basic information of users.

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

Return description

Normally, WeChat will return the following JSON packets to the official account:

Parameter description

In case of error, wechat will return error code and other information. The example of JSON packet is as follows (this example is an invalid appid error):

According to the above information, we define a user information class to store the basic information of users.

Let's first look at the interface for obtaining user information:

https://api.weixin.qq.com/cgi-bin/user/info?access_token=ACCESS_TOKEN&openid=OPENID&lang=zh_CN

According to the analysis, a token is required to obtain the basic information of the user.

HTTPS request, trust manager required

Encapsulates a public class:

Methods to obtain basic user information:

Test method: note that replace the following with your own appid and secret key.

The effects are as follows:

Openid: ook yujvd9geegh6nrien gnlrvw attention status: 1 attention time: 1449021142 nickname: Feng Shao gender: 1 country: China Province: Guangdong city: Guangzhou language: zh_ Cn Avatar: http://wx.qlogo.cn/mmopen/lOZIEvyfCa7aZQ7CkiamdpQicUDnGDEC0nzb7ZALjdl3TzFVFEHWM1AFqEXnicNIDeh0IQYTt0NrIP06ibg4W5WflASfFfX9qqib0/0

The above content introduces the wechat public platform to develop the actual java version of wechat to obtain basic user information. I hope the sharing of this article will help you in your future work and learning. At the same time, thank you for your support for the programming tips website all the time.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>