zoukankan      html  css  js  c++  java
  • php判断用户是否关注微信公众号

    方法一:

    <?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 "已关注";

        }else{

        echo "未关注"; 

     }

     

     

    方法二:

    < ? 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'未关注!';

    }

    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('获取access_token发生错误:错误代码'.$json - > errcode.',微信返回错误信息:'.$json - > errmsg);

     }

     return $json - > access_token;

    }

    ? >

  • 相关阅读:
    五角星评分小例子
    手风琴案列
    隔行变色
    全选和单选(有一个单选没有打钩,全选也自动不打钩)
    随机数封装
    数组的升降序排列
    js面向对象倒计时与文字左右滚动
    linux知识点总结与随笔(关注linux爱好者公众号的一些笔记)
    线程与进程(我的理解)
    @property在python类中的应用
  • 原文地址:https://www.cnblogs.com/jiaoda/p/10769089.html
Copyright © 2011-2022 走看看