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;
        }
    技术最菜,头发最少
  • 相关阅读:
    函数宏实现循环左移
    函数宏判断小端
    Linux下32位与64位数据类型大小
    转:C语言嵌入式系统编程之软件架构篇
    转:详解大端小段模式
    time函数计算时间
    匈牙利命名法
    20131030
    20131029
    20131028
  • 原文地址:https://www.cnblogs.com/gushengyan/p/9635213.html
Copyright © 2011-2022 走看看