zoukankan      html  css  js  c++  java
  • 微信公众号方法(不定时更新)

    1.判断用户是否关注(其实这一步也拉取了用户信息,不过项目需要单独实时查询,所以单独写了)

        public function isAttention($openid){
            $model = new HomeConfWeixin();
            $access_token = $model->getAccesstoken();
            $url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=".$access_token."&openid=".$openid."&lang=zh_CN";
            $result = $model->http_get($url);
            $result = json_decode($result);
            return $result->subscribe;
        }

    2.获取accessToken

        //获取accesstoken
        public function getAccesstoken()
        {
            $conf=M("jx_wxconf");
            $appid=$conf->where(array("varname"=>"appid"))->getField('value');
            $secret=$conf->where(array("varname"=>"appsecret"))->getField('value');
            $expires_in=$conf->where(array("varname"=>"expires_in"))->getField('value');
            $oaccess_token=$conf->where(array("varname"=>"access_token"))->getField('value');
    
            if ($expires_in < time() or ! $expires_in)
            {
                $url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret;
                $info=$this->curl_post($url,$post_data='');
                $dataJson = json_decode($info, true);
                if ($dataJson) {
                    $access_token = $dataJson['access_token'];
                    $data['value'] = time() + 3600; //保存1小时
                    M("jx_wxconf")->where(array("varname"=>"expires_in"))->save($data);
                    $d['value'] = $dataJson['access_token'];
                    M("jx_wxconf")->where(array("varname"=>"access_token"))->save($d);
                }
            } else {
                $access_token = $oaccess_token;
            }
            return $access_token;
        }
    技术最菜,头发最少
  • 相关阅读:
    设置debian6源
    debian7编译安装tengine添加lua和ldap模块
    elasticsearch5使用snapshot接口备份索引
    logstash5生成init脚本后台启动
    Xpack集成LDAP
    debian安装filebeat5.5收集nginx日志
    kibana5画图
    安装Xtrabackup,设置定时备份msyql数据库
    编译安装nrpe,配置监控mysql端口和主从状态
    编译安装keepalived,实现双主mysql高可用
  • 原文地址:https://www.cnblogs.com/gushengyan/p/9635213.html
Copyright © 2011-2022 走看看