/** * Redirect the user of the application to the WeChat's authentication screen. * * @param string $to * @param string $scope * * @return RedirectResponse * * @throws InvalidArgumentException */ public function redirect($to, $scope = 'snsapi_userinfo') { if (!in_array($scope, $this->scopes)) { throw new InvalidArgumentException("Invalid oauth scope:'{$scope}'"); } $this->request->getSession()->set('state', $state = Str::random(40)); return new RedirectResponse($this->buildAuthUrlFromBase($to, $scope, $state) . '#wechat_redirect'); }