config = Config::getInstance()->get('passport'); //$this->objMemcached = new Memcached(); //$this->refer = 'passportRefer'; } public function doGet() { $refer = Request::g ( 'referer' ); $cas_uid = Request::g ( 'cas_uid' ); $tokenid = Request::g ( 'tokenid' ); $objUserData = new UserInfo(); $userData = $objUserData -> get($cas_uid); //$this->objMemcached->set($this->refer, $refer); $host = $this->config['url']; $param = $this->config['param']; if ($param) { foreach ($param as $k => $v) { if ($v == '{passport_uid}') { if (isset($userData['passport_uid']) && $userData['passport_uid']) { $param[$k] = $userData['passport_uid']; } else { $param[$k] = $v = $tokenid; } } if (!$v) { unset($param[$k]); } } } //echo $this->config['url'] . "\r\n"; //print_r($param); $data = $this->httpPost($host, $param); $data = json_decode($data, true); /* $data['data'] = array ( 'nickName' => 'rabin', 'avatar' => 'http://echarts.baidu.com/images/logo.png', 'tokenId' => '111111', ); */ if (isset($data['data']) && isset($data['data']['tokenId']) && $data['data']['tokenId']) { $refer = urldecode($refer); $refer = str_replace('&', '&', $refer); $param['nickname'] = $data['data']['nickName']; $param['headimgurl'] = $data['data']['avatar']; $param['uid'] = $data['data']['tokenId']; $refer .= '&' . http_build_query($param); header ( "Location: " . $refer); } else { print_r($data);die; } } private function httpGet($url) { $curl = curl_init(); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_TIMEOUT, 500); curl_setopt($curl, CURLOPT_URL, $url); $res = curl_exec($curl); curl_close($curl); return $res; } private function httpPost($url, $param) { $curl = curl_init(); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_TIMEOUT, 500); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $param); $res = curl_exec($curl); curl_close($curl); return $res; } }