public static function getCurrentUrl()
{
$protocol = isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? 'https://' : 'http://';
return $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
}
/** * 获取授权 URL */ public function getAuthorizeUrl() { if (null === $this->state) { $this->state = Util::getRandomString(16); } $this->stateManager->setState($this->state); $query = array('appid' => $this->appid, 'redirect_uri' => $this->redirectUri ?: Util::getCurrentUrl(), 'response_type' => 'code', 'scope' => $this->resolveScope(), 'state' => $this->state); return $this->resolveAuthorizeUrl() . '?' . http_build_query($query); }