123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- <?php
- namespace Cas\Controller;
- use KIF\Cache\Memcached;
- use KIF\Core\Config;
- use KIF\Core\Request;
- use Cas\Dao\UserInfo;
- /**
- *
- * passport 从第三方获取userid
- * @author rabin
- *
- */
- class Passport extends Controller{
-
- private $config;
-
- public function __construct() {
- $this->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]);
- }
- }
- }
- */
- $param['authorizedCode'] = 'fulishe';
- $param['tokenId'] = $tokenid;
- //echo $this->config['url'] . "\r\n";
- //print_r($param);
- $param['tokenId'] = preg_replace('/[\x{10000}-\x{10FFFF}]/u', '', $param['tokenId']);
- $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']['userId']) && $data['data']['userId']) {
- $refer = urldecode($refer);
- $refer = str_replace('&', '&', $refer);
- $param['nickname'] = $data['data']['nickName'];
- $param['headimgurl'] = $data['data']['avatar'];
- $param['uid'] = $data['data']['userId'];
- $refer .= '&' . http_build_query($param);
- header ( "Location: " . $refer);
- } else {
- echo $tokenid . "<br />";
- 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;
- }
- }
|