Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get token from EasyWeChat AccessToken class. #53

Merged
merged 2 commits into from
May 16, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 41 additions & 9 deletions src/Providers/WeChatOpenPlatformProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,26 @@ class WeChatOpenPlatformProvider extends WeChatProvider
/**
* Component AppId.
*
* @deprecated 2.0 Will be removed in the future
*
* @var string
*/
protected $componentAppId;

/**
* Component Access Token.
*
* @deprecated 2.0 Will be removed in the future
*
* @var string
*/
protected $componentAccessToken;

/**
* @var \EasyWeChat\OpenPlatform\AccessToken|array
*/
protected $credentials;

/**
* {@inheritdoc}.
*/
Expand All @@ -43,24 +52,27 @@ class WeChatOpenPlatformProvider extends WeChatProvider
* Create a new provider instance.
* (Overriding).
*
* @param \Symfony\Component\HttpFoundation\Request $request
* @param string $clientId
* @param array $componentCredits
* @param string|null $redirectUrl
* @param \Symfony\Component\HttpFoundation\Request $request
* @param string $clientId
* @param \EasyWeChat\OpenPlatform\AccessToken|array $credentials
* @param string|null $redirectUrl
*/
public function __construct(Request $request, $clientId, array $componentCredentials, $redirectUrl = null)
public function __construct(Request $request, $clientId, $credentials, $redirectUrl = null)
{
parent::__construct($request, $clientId, null, $redirectUrl);

list($this->componentAppId, $this->componentAccessToken) = $componentCredentials;
$this->credentials = $credentials;
if (is_array($credentials)) {
list($this->componentAppId, $this->componentAccessToken) = $credentials;
}
}

/**
* {@inheritdoc}.
*/
public function getCodeFields($state = null)
{
$this->with(['component_appid' => $this->componentAppId]);
$this->with(['component_appid' => $this->componentAppId()]);

return parent::getCodeFields($state);
}
Expand All @@ -80,10 +92,30 @@ protected function getTokenFields($code)
{
return [
'appid' => $this->clientId,
'component_appid' => $this->componentAppId,
'component_access_token' => $this->componentAccessToken,
'component_appid' => $this->componentAppId(),
'component_access_token' => $this->componentAccessToken(),
'code' => $code,
'grant_type' => 'authorization_code',
];
}

/**
* Get component app id.
*
* @return string
*/
protected function componentAppId()
{
return $this->componentAppId ?: $this->credentials->getAppId();
}

/**
* Get component access token.
*
* @return string
*/
protected function componentAccessToken()
{
return $this->componentAccessToken ?: $this->credentials->getToken();
}
}