/** * 获取当前URL * * @return string */ public function getUrl() { if ($this->url) { return $this->url; } return Url::current(); }
public function url() { $url = new Url('wx8e883164d9342b1f', 'e73145bd0fdef28ea54b0b3608061c33'); $shortUrl = $url->short('http://overtrue.me/open-source'); var_dump($shortUrl); }
/** * 生成outh URL. * * @param string $to * @param string $scope * @param string $state * * @return string */ public function url($to = null, $scope = 'snsapi_userinfo', $state = 'STATE') { $to !== null || ($to = Url::current()); $params = array('appid' => $this->appId, 'redirect_uri' => $to, 'response_type' => 'code', 'scope' => $scope, 'state' => $state); return self::API_URL . '?' . http_build_query($params) . '#wechat_redirect'; }
/** * 直接跳转 * * @param string $to * @param string $scope * @param string $state */ public function redirect($to = null, $scope = 'snsapi_userinfo', $state = 'STATE') { $to !== null || ($to = Url::current()); header('Location:' . $this->url($to, $scope, $state)); exit; }