PHP How to determine whether users are concerned about WeChat public number

Source: Internet
Author: User
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.

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.