Many of today’s activities guide users to follow public accounts in order to participate in the activities. So how can we judge that users have followed public accounts? This article will provide you with php code to solve the problem.
Official interface description
Get basic user information (including UnionID mechanism)
http://mp.weixin.qq.com/wiki/14/bb5031008f1494a59c6f71fa0f319c66.html
1. As long as there is a basic access_token and user openid It can be judged whether the user follows the official account
2. The interface URL used is: https://api.weixin.qq.com/cgi-bin/user/info?access_token=$token&openid=$openid3. Determine the fields returned by the interface Whether subscribe is 1. [1 following, 0 not following]
Note:
1. To determine that the user login method is silent authorization, the user is unaware, and thus get the user's openid;
2. To determine the user's login, WeChat authentication is required Service account support, subscription account does not work;
The following is a code example
< ? 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'未关注!'; } 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('获取access_token发生错误:错误代码'.$json - > errcode.',微信返回错误信息:'.$json - > errmsg); } return $json - > access_token; } ? >
The above is the entire content of this article, I hope it will be helpful to everyone's study.
The above introduces the development of WeChat public account. WeChat public account determines whether the user has paid attention to PHP code analysis, including the content of WeChat public account development. I hope it will be helpful to friends who are interested in PHP tutorials.