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, you can determine whether the user follows the public account
2. The interface url used is: 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 following, 0 not following]
Note:
1. It is determined that the user login method is silent authorization, and the user is unaware. To get the user's openid;
2. To determine the user's login, you need the support of a WeChat authentication service account, a subscription account will 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