Now, many of the activities are directed users to focus on the public number, in order to participate in the activities, that how to judge the user concerned about the public number? 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 the basis of access_token and user OpenID can determine whether the user is concerned about the public number
2, the use of the interface URL is:https://api.weixin.qq.com/cgi-bin/user/info?access_token= $token &openid= $openid
3, to determine whether the interface returned by the field subscribe is 1. "1 attention, 0 not concerned"
Note:
1, the way to determine the user login for the silent authorization, the user does not perceive, thereby getting the user's OpenID;
2, judge the user login, the need for micro-letter authentication Service number support, the subscription number is not;
The following is a 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 ' is not concerned!
';
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 (' Get Access_token errors: Error code '. $json-> Errcode. ', micro-letter Returns an error message: '. $js
On-> ErrMsg);
Return $json-> Access_token; }
? >
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.