This article is mainly for everyone in detail about PHP to determine whether users pay attention to the public number, with a certain reference value, interested in small partners can refer to
The recent need to do a platform for voting, to be concerned about the public to participate in voting, then, how to determine whether users are concerned about the public number?
The first idea is to search the list for the participant's OpenIDby getting the public number watchlist.
But one immediate problem is that this approach needs to get a list of concerns every time, and it's a bit more difficult when the number of public fans is a bit more.
Use the PHP method below to determine whether the user is concerned about the public number:
<?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 "has been concerned"; } else{ echo "not concerned"; }
Here is a 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 ' not paying attention! ';} Private Function _getaccesstoken () {$where = array (' token ' = > $this-> Token); $this-> Thiswxuser = M (' Wxuse R ')-> 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 (' Get Access_token: Error code '. $json-> Errcode. ', return error message: '. $json- > ErrMsg); } return $json-> Access_token;}? >
Summary: The above is the entire content of this article, I hope to be able to help you learn.