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