PHP to determine whether the user is concerned about the _php of micro-credit public number example

Source: Internet
Author: User
Tags error code openid

The recent voting campaign to do a micro-trust platform needs to be focused on public numbers before voting, so how can you tell if the user is concerned about the public number?

The first idea was to get a public-number attention list and then search the list for the participants ' OpenID.

But the immediate problem is that this approach requires a list of concerns every time, and when the public number of fans is relatively long, this approach is more strenuous.

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 "attention";
    } else{
    echo "not concerned";
    
 }

Here is the 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 ' 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: '. $jso
 N-> 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.