Use php to determine whether a user pays attention to the WeChat official account

Source: Internet
Author: User
Tags openid
This article mainly introduces php to determine whether users are interested in the public account, which has some reference value. interested friends can refer to a recent voting activity on the platform, you must pay attention to the public account before voting. how can you determine whether the user pays attention to the public account?

The first idea is to retrieve the public account's follow list and then search for the participant's openid in the list.

However, a problem is found immediately. this method requires a list of followers every time. In addition, when there are a large number of followers of the public account, this method is more difficult.

The following uses the php method to determine whether the user pays attention to the public account:

 Access_token; $ subscribe_msg = "https://api.weixin.qq.com/cgi-bin/user/info? Access_token = $ token & openid =$ _ GET [openid] "; $ subscribe = json_decode (file_get_contents ($ subscribe_msg); $ gzxx = $ subscribe-> subscribe; // if ($ gzxx = 1) {echo "followed";} else {echo "not followed ";}

The second code case is as follows:

<? 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.

Related articles:

Question about how to determine whether a user entered a page for the first time?

Use PHP to determine the user's first login on the day

How to determine whether a user accesses a mobile phone through the php website

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.