Develop WeChat public platform to obtain basic user information

Source: Internet
Author: User
Tags openid
This article describes how to obtain basic information about users on the public platform, including nicknames, portraits, gender, country, province, city, and language. This article describes how to obtain basic information about users on the public platform, including nicknames, portraits, gender, country, province, city, and language.
The methods in this article include subscription numbers, service numbers, and custom menus. no matter whether you have advanced interface permissions, you can obtain basic user information without simulating logon.

In this article, we should note that there are two different Access tokens which are generated in different ways. one is the access_token obtained by using AppID and AppSecret, one is the access_token generated in OAuth2.0 Authorization. Fang times studio is called global Access Token and authorized Access Token respectively.

1. obtain basic user information through global Access Token

You can obtain your OpenID when following and replying to a message.

     
  gh_b629c48b653e
      
  ollB4jv7LA3tydjviJp5V9qTU_kA
      
  
   1372307736
      
  event
      
  subscribe
      
  
  
 

FromUserName indicates the OpenID.

Then, use the access_token interface to obtain the Global Access Token.

Returned results:

{    "access_token": "NU7Kr6v9L9TQaqm5NE3OTPctTZx797Wxw4Snd2WL2HHBqLCiXlDVOw2l-Se0I-WmOLLniAYLAwzhbYhXNjbLc_KAA092cxkmpj5FpuqNO0IL7bB0Exz5s5qC9Umypy-rz2y441W9qgfnmNtIZWSjSQ",    "expires_in": 7200}

Use global ACCESS_TOKEN to obtain the detailed information of OpenID.

The returned result is as follows:

{"Subscribe": 1, "openid": "oLVPpjqs2BhvzwPj5A-vTYAX4GLc", "nickname": "Baby Hedgehog", "sex": 1, "language": "zh_CN ", "city": "Shenzhen", "province": "Guangdong", "country": "China", "headimgurl": "http://wx.qlogo.cn/mmopen/JcDicrZBlREhnNXZRudod9PmibRkIs5K2f1tUQ7lFjC63pYHaXGxNDgMzjGDEuvzYZbFOqtUXaxSdoZG6iane5ko9H30krIbzGv/0", "subscribe_time": 1386160805}

Now, obtain the basic information of the user.

This method is most suitable for users to reply to a message that welcomes attention + user nickname when paying attention, as shown in the response when paying attention to the following public account. Scan the QR code to try it out.

{    "access_token": "OezXcEiiBSKSxW0eoylIeAsR0GmYd1awCffdHgb4fhS_KKf2CotGj2cBNUKQQvj-G0ZWEE5-uBjBz941EOPqDQy5sS_GCs2z40dnvU99Y5AI1bw2uqN--2jXoBLIM5d6L9RImvm8Vg8cBAiLpWA8Vw",    "expires_in": 7200,    "refresh_token": "OezXcEiiBSKSxW0eoylIeAsR0GmYd1awCffdHgb4fhS_KKf2CotGj2cBNUKQQvj-G0ZWEE5-uBjBz941EOPqDQy5sS_GCs2z40dnvU99Y5CZPAwZksiuz_6x_TfkLoXLU7kdKM2232WDXB3Msuzq1A",    "openid": "oLVPpjqs9BhvzwPj5A-vTYAX3GLc",    "scope": "snsapi_userinfo,"}

Use the authorized Access Token to obtain user information.

The returned result is as follows:

{"Openid": "oLVPpjqs9BhvzwPj5A-vTYAX3GLc", "nickname": "Baby Hedgehog", "sex": 1, "language": "zh_CN", "city": "Shenzhen ", "province": "Guangdong", "country": "China", "headimgurl": "http://wx.qlogo.cn/mmopen/utpKYf69VAbCRDRlbUsPsdQN38DoibCkrU6SAMCSNx558eTaLVM8PyM6jlEGzOrH67hyZibIZPXu4BK1XNWzSXB3Cs4qpBBg18/0", "privilege": []}

The user information has been obtained.

The final user information is as follows:

The returned result is as follows:

{    "access_token": "OezXcEiiBSKSxW0eoylIeAsR0GmYd1awCffdHgb4fhS_KKf2CotGj2cBNUKQQvj-oJ9VmO-0Z-_izfnSAX_s0aqDsYkW4s8W5dLZ4iyNj5Y6vey3dgDtFki5C8r6D0E6mSVxxtb8BjLMhb-mCyT_Yg",    "expires_in": 7200,    "refresh_token": "OezXcEiiBSKSxW0eoylIeAsR0GmYd1awCffdHgb4fhS_KKf2CotGj2cBNUKQQvj-oJ9VmO-0Z-_izfnSAX_s0aqDsYkW4s8W5dLZ4iyNj5YBkF0ZUH1Ew8Iqea6x_itq13sYDqP1D7ieaDy9u2AHHw",    "openid": "oLVPpjqs9BhvzwPj5A-vTYAX3GLc",    "scope": "snsapi_base"}

Returned results:

{    "access_token": "NU7Kr6v9L9TQaqm5NE3OTPctTZx797Wxw4Snd2WL2HHBqLCiXlDVOw2l-Se0I-WmOLLniAYLAwzhbYhXNjbLc_KAA092cxkmpj5FpuqNO0IL7bB0Exz5s5qC9Umypy-rz2y441W9qgfnmNtIZWSjSQ",    "expires_in": 7200}

The returned result is as follows:

{"Subscribe": 1, "openid": "oLVPpjqs2BhvzwPj5A-vTYAX4GLc", "nickname": "Baby Hedgehog", "sex": 1, "language": "zh_CN ", "city": "Shenzhen", "province": "Guangdong", "country": "China", "headimgurl": "http://wx.qlogo.cn/mmopen/JcDicrZBlREhnNXZRudod9PmibRkIs5K2f1tUQ7lFjC63pYHaXGxNDgMzjGDEuvzYZbFOqtUXaxSdoZG6iane5ko9H30krIbzGv/0", "subscribe_time": 1386160805}

Basic user information is obtained successfully.

This is suitable for the use of service numbers that have been authorized by OAuth2.0 web pages, and the "login" page is not displayed. Reduce user interruption.

4. which method is most suitable?

For reference

1. service number
Advanced interface permissions: three types of message reply can be customized. use method 3 in the menu (China Merchants Bank credit card center use method 3, use method 2 in Kangsheng micro community)
No advanced interface permission: use method 2 in the custom menu of message reply (do not have the advanced permission to borrow others' Appid and AppSecret)
2. subscription number
Authenticated permission to get user information use method 1 in message reply User-defined menu use method 2 (no advanced permission needs to borrow others' Appid and AppSecret)
Unauthenticated, unauthenticated, user information permission, no method in the custom menu of Method 2 in message reply. (if you do not have advanced permissions, you need to borrow others' Appid and AppSecret. this is what Fang times studio uses.

The above is the details of getting basic user information from the development public platform. For more information, see other related articles on php Chinese network!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.