WeChat official account determines whether users are paying attention to php code parsing. public php_PHP tutorial

Source: Internet
Author: User
The public account determines whether users are concerned about php code parsing and public php. The public account determines whether users are paying attention to php code parsing. many of the current activities of public php guide users to pay attention to public accounts before they can participate in the activities, how can we determine whether the user's public account is concerned with php code parsing?

In today's activities, many users are guided to pay attention to the public accounts before they can participate in the activities. how can we determine whether users have followed the public accounts? This article provides php code to solve the problem.

Official interface description
Obtain basic user information (including the UnionID mechanism)

Http://mp.weixin.qq.com/wiki/14/bb5031008f1494a59c6f71fa0f319c66.html

1. as long as there are basic access_token and user openid, you can determine whether the user pays attention to the public account.
2, the use of interface url: https://api.weixin.qq.com/cgi-bin/user/info? Access_token = $ token & openid = $ openid
3. determine whether the subscribe Field returned by the interface is 1. [1 followed, 0 not followed]

Note:
1. determine that the user's login method is silent authorization, and the user is unaware of it, so as to obtain the user's openid;
2. determine whether a user logs on. The service number must be supported by the authentication service number. the subscription number cannot be used;

The following is a code case

<? Php $ access_token = $ this-> _ getAccessToken (); $ subscribe_msg = 'https: // api.weixin.qq.com/cgi-bin/user/info? Access_token = '. $ access_token. '& openid = '. $ _ SESSION ['wecha _ id']; $ subscribe = json_decode ($ this-> curlGet ($ subscribe_msg); $ zyxx = $ subscribe-> subscribe; if ($ zyxx! = 1) {echo 'not followed! ';} Private function _ getAccessToken () {$ where = array ('token' => $ this-> token); $ this-> thisWxUser = M ('wxuser ') -> where ($ where)-> find (); $ url_get = 'https: // api.weixin.qq.com/cgi-bin/token? Grant_type = client_credential & appid = '. $ this-> thisWxUser ['appid ']. '& secret = '. $ this-> thisWxUser ['appsecret']; $ json = json_decode ($ this-> curlGet ($ url_get); if (! $ Json-> errmsg) {} else {$ this-> error ('error occurred when obtaining access_token: error code '. $ json-> errcode. ', error message returned :'. $ json-> errmsg);} return $ json-> access_token ;}? >

The above is all the content of this article, hoping to help you learn.


Today's events, many of which have guided users to pay attention to the public accounts before they can participate in the activities. how can they determine the users...

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.