Recently, there will be a voting event on the WeChat platform. You need to follow the official account before you can participate in the voting. So, how to judge whether the user has followed the official account?
The first idea is to get the public account’s watch list and then search whether there is a participant’s openid in the list.
But I immediately discovered a problem, that is, this method requires getting the watch list every time, and when the official account has a lot of fans, this method is more difficult.
The following uses the PHP method to determine whether the user has followed the public account:
<?php $access_token = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=XXXXXXXXXXXXXXXXXX&secret=XXXXXXXXXXXXXXXXXXXXXXXXXX"; $access_msg = json_decode(file_get_contents($access_token)); $token = $access_msg->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 "已关注"; }else{ echo "未关注"; }
The following is the second 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'未关注!'; } 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. I hope everyone will support this site.
The above introduces PHP to determine the character type. PHP determines whether the user follows the WeChat public account, including the content of PHP to determine the character type. I hope it will be helpful to friends who are interested in PHP tutorials.