Micro-credit public number to determine whether the user has been concerned about PHP code parsing _php Instance

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.