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;
        }
    技术最菜,头发最少
  • 相关阅读:
    C++构造与析构 yongmou
    坏习惯 yongmou
    Python 字符串方法
    python 列表推导式轻量级循环
    python 循环遍历字典元素
    python 短路逻辑和条件表达式
    python 迭代器
    一些关于面向对象设计的思考
    python map内建函数
    Python 列表
  • 原文地址:https://www.cnblogs.com/gushengyan/p/9635213.html
Copyright © 2011-2022 走看看