return_url = "http://".$_SERVER['HTTP_HOST']."/index.php?m=Mobile&c=LoginApi&a=callback&oauth=qq"; // else // $this->return_url = "http://".$_SERVER['HTTP_HOST']."/index.php?m=Home&c=LoginApi&a=callback&oauth=qq"; $this->return_url = "http://".$_SERVER['HTTP_HOST']."/index.php/Home/LoginApi/callback/oauth/qq"; $this->app_id = $config['app_id']; $this->app_secret = $config['app_secret']; } //构造要请求的参数数组,无需改动 public function login(){ $_SESSION['state'] = md5(uniqid(rand(), TRUE)); //拼接URL $dialog_url = "https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id=" . $this->app_id . "&redirect_uri=" . urlencode($this->return_url) . "&state=" . $_SESSION['state']; echo(""); exit; } public function respon(){ if($_REQUEST['state'] == $_SESSION['state']) { $code = $_REQUEST["code"]; //拼接URL $token_url = "https://graph.qq.com/oauth2.0/token?grant_type=authorization_code&" . "client_id=" . $this->app_id . "&redirect_uri=" . urlencode($this->return_url) . "&client_secret=" . $this->app_secret . "&code=" . $code; $response = $this->get_contents($token_url); if (strpos($response, "callback") !== false) { $lpos = strpos($response, "("); $rpos = strrpos($response, ")"); $response = substr($response, $lpos + 1, $rpos - $lpos -1); $msg = json_decode($response); if (isset($msg->error)) { echo "