Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue committed Mar 16, 2021
1 parent 201b084 commit 4246be1
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/Providers/WeChat.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class WeChat extends Base
public function __construct(array $config)
{
parent::__construct($config);

if ($this->getConfig()->has('component')) {
$this->prepareForComponent((array) $this->getConfig()->get('component'));
}
}

/**
Expand All @@ -48,7 +52,7 @@ public function withCountryCode()
* @param string $code
*
* @return array
* @throws \Overtrue\Socialite\Exceptions\AuthorizeFailedException
* @throws \Overtrue\Socialite\Exceptions\AuthorizeFailedException|\GuzzleHttp\Exception\GuzzleException
*/
public function tokenFromCode(string $code): array
{
Expand All @@ -61,10 +65,11 @@ public function tokenFromCode(string $code): array
* @param array $componentConfig ['id' => xxx, 'token' => xxx]
*
* @return \Overtrue\Socialite\Providers\WeChat
* @throws \Overtrue\Socialite\Exceptions\InvalidArgumentException
*/
public function withComponent(array $componentConfig)
{
$this->component = $componentConfig;
$this->prepareForComponent($componentConfig);

return $this;
}
Expand Down Expand Up @@ -100,7 +105,6 @@ 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']]));
}

Expand All @@ -127,7 +131,7 @@ protected function getTokenUrl(): string
* @param string $code
*
* @return \Overtrue\Socialite\User
* @throws \Overtrue\Socialite\Exceptions\AuthorizeFailedException
* @throws \Overtrue\Socialite\Exceptions\AuthorizeFailedException|\GuzzleHttp\Exception\GuzzleException
*/
public function userFromCode(string $code): User
{
Expand Down Expand Up @@ -221,15 +225,9 @@ protected function getTokenFromCode(string $code): ResponseInterface
]);
}

protected function prepareForComponent()
protected function prepareForComponent(array $component)
{
if (!$this->getConfig()->has('component')) {
return;
}

$config = [];
$component = $this->getConfig()->get('component');

foreach ($component as $key => $value) {
if (\is_callable($value)) {
$value = \call_user_func($value, $this);
Expand Down

0 comments on commit 4246be1

Please sign in to comment.