• 微信取得用户是否关注公众号函数


    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");
        }  
            
        }
  • 相关阅读:
    Java操作excel
    (13)C++ 多态
    (12)C++ 继承
    (18)C++ string和标准模板库
    parseInt(str),parseFloat(str)
    JavaScript substring() 方法
    JavaScript遍历对象中所有元素
    JavaScript中的number跟string
    mybatis动态sql
    Android数据存储之Android 6.0运行时权限下文件存储的思考
  • 原文地址:https://www.cnblogs.com/raphael1982/p/8301629.html
Copyright © 2020-2023  润新知