__construct(); } function index_f() { $_SESSION["oauthuser_info"]=false; $code = $_GET['code']; $state = $_GET['state']; //换成自己的接口信息 $appid = ''; $appsecret = ''; if($this->sys_config[Appid]&&strlen($this->sys_config[Appid])>1){ $appid=$this->sys_config[Appid]; $appsecret=$this->sys_config[Appsecret]; }else if($this->STCModel->Appid) { $appid=$this->STCModel->Appid; $appsecret=$this->STCModel->Appsecret; } if (empty($code)) $this->error('授权失败'); $token_url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid='.$appid.'&secret='.$appsecret.'&code='.$code.'&grant_type=authorization_code'; $token = json_decode(file_get_contents($token_url)); if (isset($token->errcode)) { echo '

错误:

'.$token->errcode; echo '

错误信息:

'.$token->errmsg; exit; } $access_token_url = 'https://api.weixin.qq.com/sns/oauth2/refresh_token?appid='.$appid.'&grant_type=refresh_token&refresh_token='.$token->refresh_token; //转成对象 $access_token = json_decode(file_get_contents($access_token_url)); if (isset($access_token->errcode)) { echo '

错误:

'.$access_token->errcode; echo '

错误信息:

'.$access_token->errmsg; exit; } $user_info_url = 'https://api.weixin.qq.com/sns/userinfo?access_token='.$access_token->access_token.'&openid='.$access_token->openid.'&lang=zh_CN'; //转成对象 $user_info = json_decode(file_get_contents($user_info_url)); if (isset($user_info->errcode)) { echo '

错误:

'.$user_info->errcode; echo '

错误信息:

'.$user_info->errmsg; exit; } $_SESSION["oauthuser_info"]=$user_info; header('location:'.$this->url('login')); //echo ""; //error('',$this->url('login')); //打印用户信息 //echo '
';
		//print_r($user_info);
		//echo '
'; } } ?>