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"); } }