/** * (non-PHPdoc) * @see \tfc\mvc\interfaces\Action::run() */ public function run() { $cookie = new Cookie('cookie'); $httpReferer = Ap::getRequest()->getTrim('http_referer'); if ($httpReferer === '') { $httpReferer = 'index.php'; } HttpCookie::add('http_referer', $httpReferer); $appid = Cfg::getApp('appid', 'wechat', 'extlogin'); $callback = Options::getSiteUrl() . '/index.php?r=member/data/wechatcallback'; $scope = 'snsapi_base'; $state = md5(uniqid(rand(), TRUE)); //CSRF protection $cookie->add('state', $state); $loginUrl = 'https://open.weixin.qq.com/connect/oauth2/authorize?response_type=code' . '&appid=' . $appid . '&redirect_uri=' . urlencode($callback) . '&state=' . $state . '&scope=' . $scope . '#wechat_redirect'; Ap::getResponse()->location($loginUrl); }
/** * (non-PHPdoc) * @see \tfc\mvc\interfaces\Action::run() */ public function run() { $cookie = new Cookie('cookie'); $httpReferer = Ap::getRequest()->getTrim('http_referer'); if ($httpReferer === '') { $httpReferer = 'index.php'; } HttpCookie::add('http_referer', $httpReferer); $appid = Cfg::getApp('appid', 'qq', 'extlogin'); $callback = Options::getSiteUrl() . '/index.php?r=member/data/qqcallback'; $scope = 'get_user_info'; $state = md5(uniqid(rand(), TRUE)); //CSRF protection $cookie->add('state', $state); $loginUrl = 'https://graph.qq.com/oauth2.0/authorize?response_type=code' . '&client_id=' . $appid . '&redirect_uri=' . urlencode($callback) . '&state=' . $state . '&scope=' . $scope; Ap::getResponse()->location($loginUrl); }
/** * 添加Cookie,如果Cookie名已经存在,则替换老值 * @param string $name * @param string $value * @param integer $expiry * @return boolean */ public function add($name, $value, $expiry = 0) { if ($this->getEncodeValue()) { $value = $this->getMef()->encode($value); } return HttpCookie::add($name, $value, $expiry, $this->getPath(), $this->getDomain(), $this->getSecure(), $this->getHttponly()); }
/** * 设置最后一次访问的列表页链接 * @param array $params * @return void */ public function setLLU(array $params = array()) { $urls = $this->getLLUs(); $router = $this->module . '_' . $this->controller . '_' . $this->actNameList; $urls[$router] = $this->urlManager->getUrl($this->action, $this->controller, $this->module, $params); while (count($urls) > self::LLU_COOKIE_COUNT) { array_shift($urls); } $value = str_replace('=', '', base64_encode(serialize($urls))); HttpCookie::add(self::LLU_COOKIE_NAME, $value); }