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