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;
        }
    技术最菜,头发最少
  • 相关阅读:
    delphi安装pngimage控件,不需要安装,只需引用就行
    怎样把PL/SQLDeveloper字体调大
    resource is out of sync with the file
    SecureCRT:[1]SecureCRT配色方案
    安装开发环境注意事项2
    插入排序
    tomcat更改端口序
    tomcat更改端口
    maven添加jar包
    java总结
  • 原文地址:https://www.cnblogs.com/gushengyan/p/9635213.html
Copyright © 2011-2022 走看看