如何判断用户是否已关注微信公众号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;
}