示例#1
0
 /**
  * 通过Cookie名获取值,如果都找不到,返回默认值
  * @param string $name
  * @param mixed $defaultValue
  * @return mixed
  */
 public function get($name, $defaultValue = null)
 {
     $value = HttpCookie::get($name, $defaultValue);
     if ($this->getEncodeValue()) {
         $value = $this->getMef()->decode($value);
     }
     return $value;
 }
示例#2
0
 /**
  * (non-PHPdoc)
  * @see \tfc\mvc\interfaces\Action::run()
  */
 public function run()
 {
     $req = Ap::getRequest();
     $cookie = new Cookie('cookie');
     $appid = Cfg::getApp('appid', 'qq', 'extlogin');
     $appkey = Cfg::getApp('appkey', 'qq', 'extlogin');
     $callback = Options::getSiteUrl() . '/index.php?r=member/data/qqcallback';
     if ($cookie->get('state') !== $req->getParam('state')) {
         exit('The state does not match. You may be a victim of CSRF.');
     }
     $tokenUrl = 'https://graph.qq.com/oauth2.0/token?grant_type=authorization_code' . '&client_id=' . $appid . '&redirect_uri=' . urlencode($callback) . '&client_secret=' . $appkey . '&code=' . $req->getParam('code');
     $response = file_get_contents($tokenUrl);
     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 '<h3>error:</h3>' . $msg->error;
             echo '<h3>msg  :</h3>' . $msg->error_description;
             exit;
         }
     }
     $params = array();
     parse_str($response, $params);
     $graphUrl = 'https://graph.qq.com/oauth2.0/me?access_token=' . $params['access_token'];
     $str = file_get_contents($graphUrl);
     if (strpos($str, 'callback') !== false) {
         $lpos = strpos($str, '(');
         $rpos = strrpos($str, ')');
         $str = substr($str, $lpos + 1, $rpos - $lpos - 1);
     }
     $user = json_decode($str);
     if (isset($user->error)) {
         echo '<h3>error:</h3>' . $user->error;
         echo '<h3>msg  :</h3>' . $user->error_description;
         exit;
     }
     $openid = $user->openid;
     $mod = Model::getInstance('Account', 'member');
     $ret = $mod->extlogin(DataAccount::PARTNER_QQ, $openid);
     if ($ret['err_no'] === DataAccount::SUCCESS_LOGIN_NUM) {
         $httpReferer = HttpCookie::get('http_referer', 'index.php');
         HttpCookie::remove('http_referer');
         Ap::getResponse()->location($httpReferer);
     } else {
         Ap::getResponse()->location('index.php?r=member/show/login');
     }
 }
示例#3
0
 /**
  * (non-PHPdoc)
  * @see \tfc\mvc\interfaces\Action::run()
  */
 public function run()
 {
     $req = Ap::getRequest();
     $cookie = new Cookie('cookie');
     $appid = Cfg::getApp('appid', 'wechat', 'extlogin');
     $appsecret = Cfg::getApp('appsecret', 'wechat', 'extlogin');
     if ($cookie->get('state') !== $req->getParam('state')) {
         exit('The state does not match. You may be a victim of CSRF.');
     }
     $tokenUrl = 'https://api.weixin.qq.com/sns/oauth2/access_token?grant_type=authorization_code' . '&appid=' . $appid . '&secret=' . $appsecret . '&code=' . $req->getParam('code');
     $resource = curl_init();
     curl_setopt($resource, CURLOPT_URL, $tokenUrl);
     curl_setopt($resource, CURLOPT_HEADER, 0);
     curl_setopt($resource, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($resource, CURLOPT_NOSIGNAL, 1);
     curl_setopt($resource, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
     $result = curl_exec($resource);
     if ($result === false) {
         $errNo = curl_errno($resource);
         $errMsg = curl_error($resource);
         curl_close($resource);
         echo '<h3>error:</h3>' . $errNo;
         echo '<h3>msg  :</h3>' . $errMsg;
         exit;
     }
     curl_close($resource);
     $user = json_decode($result);
     $openid = $user->openid;
     $mod = Model::getInstance('Account', 'member');
     $ret = $mod->extlogin(DataAccount::PARTNER_WECHAT, $openid);
     if ($ret['err_no'] === DataAccount::SUCCESS_LOGIN_NUM) {
         $httpReferer = HttpCookie::get('http_referer', 'index.php');
         HttpCookie::remove('http_referer');
         Ap::getResponse()->location($httpReferer);
     } else {
         Ap::getResponse()->location('index.php?r=member/show/login');
     }
 }
示例#4
0
 /**
  * 获取Cookie中所有的列表页链接
  * @return array
  */
 public function getLLUs()
 {
     $value = HttpCookie::get(self::LLU_COOKIE_NAME);
     if ($value !== null) {
         $urls = unserialize(base64_decode($value));
         if (is_array($urls)) {
             return $urls;
         }
     }
     return array();
 }