diff --git a/src/Providers/WeChat.php b/src/Providers/WeChat.php index b8df506..aaef931 100644 --- a/src/Providers/WeChat.php +++ b/src/Providers/WeChat.php @@ -23,7 +23,6 @@ class WeChat extends Base public function __construct(array $config) { parent::__construct($config); - $this->prepareForComponent(); } /** @@ -58,6 +57,23 @@ public function tokenFromCode(string $code): array return $this->normalizeAccessTokenResponse($response->getBody()->getContents()); } + /** + * @param array $componentConfig ['id' => xxx, 'token' => xxx] + * + * @return \Overtrue\Socialite\Providers\WeChat + */ + public function withComponent(array $componentConfig) + { + $this->component = $componentConfig; + + return $this; + } + + public function getComponent() + { + return $this->component; + } + protected function getAuthUrl(): string { $path = 'oauth2/authorize'; @@ -84,6 +100,7 @@ protected function buildAuthUrlFromBase(string $url): string protected function getCodeFields(): array { if (!empty($this->component)) { + $this->prepareForComponent(); $this->with(array_merge($this->parameters, ['component_appid' => $this->component['id']])); }