zoukankan      html  css  js  c++  java
  • 微信取得用户是否关注公众号函数

    public function getUserInfo() {
    
             $bianhao = I('get.bianhao');
           
    //        echo '<strong style="color:#ff0000">订单号<span >'.$bianhao.'</span></strong>';
            $appid = 'xxxxxxxxxxxxx';
            $appsecret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx';
            $code = $_GET["code"];
            $this->assign('code', $code);
    //        show_bug($code,"code");
    //echo $code;
    //第一步:取全局access_token
            $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $appsecret;
            $token = getJson($url);
    //        show_bug($token,"token");
    //        echo $token["access_token"];
    //第二步:取得openid
            $oauth2Url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" . $appid . "&secret=" . $appsecret . "&code=" . $code . "&grant_type=authorization_code";
            $oauth2 = getJson($oauth2Url);
    //        show_bug($oauth2,"oauth2");
    
    //第三步:根据全局access_token和openid查询用户信息  
            $access_token = $token["access_token"];
            $openid = $oauth2['openid'];
    //        show_bug($openid,"openid");
            $_SESSION['o'] = $openid;
    //                echo $_SESSION['o']."这是O<br>";
            $get_user_info_url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=" . $access_token . "&openid=" . $_SESSION['o'] . "&lang=zh_CN";
            $userinfo = getJson($get_user_info_url);
    //        show_bug($userinfo,"userinfo");
    //echo $openid;
    //打印用户信息
            $subscribe = intval($userinfo['subscribe']);
        if($_SESSION['o']){
            if ($subscribe==1) {
    
                $guanzhu="-100%";
    //            show_bug($guanzhu,"你已经关注");
                $this->assign('guanzhu',$guanzhu);
                $this->assign('bianhao', $bianhao);
    //            $this->display("Order/index");
                $this->display("Order/getUserInfo");
            } else {
                $guanzhu="0";
    //            show_bug($guanzhu,"你没有关注");
                $this->assign('bianhao', $bianhao);
                $this->assign('guanzhu',$guanzhu);
    //            $this->display("Order/getUserInfo");
                $this->display("Order/index");
            }
        }else  {
    //        show_bug("微信seesion断开");
             $this->assign('bianhao', $bianhao);
            $this->display("Order/index");
        }  
            
        }
  • 相关阅读:
    [转]laravel 4之视图及Responses
    Laravel 安装指南
    [转]CodeIgniter与Zend Acl结合实现轻量级权限控制
    OSCHina技术导向:Java电子商务平台OFBiz
    OSCHina技术导向:Java开源QQ工具iQQ
    OSCHina技术导向:web内容管理系统Magnolia
    OSCHina技术导向:Java轻量web开发框架——JFinal
    OSCHina技术导向:Java模板引擎velocity
    OSCHina技术导向:Java全文搜索框架Lucene
    OSChina技术导向:Java图表框架JFreeChart
  • 原文地址:https://www.cnblogs.com/raphael1982/p/8301629.html
Copyright © 2011-2022 走看看