• 判断微信用户是否关注微信号


    1.先获取公众号的access_token

    private $appid='';
    private $secret='';
    private function getAccessToken() { // access_token 应该全局存储与更新,以下代码以写入到文件中做示例 $data = S('access_token'); if ($data['expire_time'] < time()) { // 如果是企业号用以下URL获取access_token // $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$this->appId&corpsecret=$this->appSecret"; $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$this->appid."&secret=".$this->secret; $res = json_decode($this->http_curl($url),true); $access_token = $res['access_token']; if ($access_token) { $data['expire_time'] = time() + 7000; $data['access_token'] = $access_token; S('access_token',$data); } } else { $access_token = $data['access_token']; } return $access_token; }

    2.再根据"https://api.weixin.qq.com/cgi-bin/user/info?access_token=".$accessToken."&openid=".$openid;  调用curl,根据返回的结果集里的subscribe的状态进行判断

     1     public function attention(){
     2         $openid=$_SESSION['weinfo']['openid'];
     3         // 获取公众号的access_token,此access_token不是用户授权后的access_token
     4         $accessToken = $this->getAccessToken();
     5         $subscribe_msg = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=".$accessToken."&openid=".$openid;
     6         $subscribe_info = $this->http_curl($subscribe_msg);
     7         $subscribe_info = json_decode($subscribe_info);
     8         if($subscribe_info->subscribe){
     9             $msg['status']=1;
    10         }else{
    11             $msg['status']=0;
    12         }
    13         return $msg;
    14     }
  • 相关阅读:
    Ajax原生XHR对象
    node-sass报错解决方法
    AngularJS中的表单验证
    javaScirpt事件详解-原生事件基础(一)
    jQuery Ajax总结
    Ruby 方法
    JS中常遇到的浏览器兼容问题和解决方法
    History对象
    转码与解码
    Location对象
  • 原文地址:https://www.cnblogs.com/dreamysky/p/5918163.html
Copyright © 2020-2023  润新知