Determine whether the user has followed the php code parsing and the Public php
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. I hope it will be helpful for your learning and support for helping customers.