WeChat public number development WeChat public to determine whether the user is concerned about PHP code parsing

Source: Internet
Author: User
Now, many of the activities to guide users to pay attention to the public, in order to participate in activities, then 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 basic access_token and user OpenID can determine whether the user is concerned about the public number
2, the interface URL to use: https://api.weixin.qq.com/cgi-bin/user/info?access_token= $token &openid= $openid 3, Determines whether the field returned by the interface subscribe is 1. "1 followers, 0 not paying attention"

Note:
1, the method of judging the user login is silent authorization, the user does not perceive, thereby obtaining the user's OpenID;
2, judge the user login, need to support the certification service number, subscription number does not work;

Here is the 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: '. $jso N-> ErrMsg); } return $json-> Access_token;}? >

The above is the whole content of this article, I hope that everyone's learning has helped.

The above describes the public number development public number to determine whether the user has been concerned about PHP code parsing, including the development of the public number of content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.